├── .gitattributes ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── src ├── main │ ├── resources │ │ ├── application.properties │ │ ├── mapping │ │ │ ├── newsMapper.xml │ │ │ ├── ReplyMapper.xml │ │ │ ├── ReviewMapper.xml │ │ │ ├── RecordMapper.xml │ │ │ ├── MessageMapper.xml │ │ │ ├── UsersMapper.xml │ │ │ ├── BookCaseMapper.xml │ │ │ ├── ScoreMapper.xml │ │ │ ├── PostMapper.xml │ │ │ └── ChapterMapper.xml │ │ └── mybatis-config.xml │ └── java │ │ └── com │ │ └── riyeyuedu │ │ ├── ReaderApplication.java │ │ ├── dao │ │ ├── NewsDao.java │ │ ├── ReplyDao.java │ │ ├── ReviewDao.java │ │ ├── MessageDao.java │ │ ├── RecordDao.java │ │ ├── ScoreDao.java │ │ ├── UserDao.java │ │ ├── ReaderDao.java │ │ ├── PostDao.java │ │ ├── ChapterDao.java │ │ ├── BookCaseDao.java │ │ └── NovelDao.java │ │ ├── security │ │ ├── JWToken.java │ │ ├── Realm.java │ │ └── JWTFilter.java │ │ ├── entity │ │ ├── LabelEntity.java │ │ ├── AttitudeEntity.java │ │ ├── BookCaseEntity.java │ │ ├── RecordEntity.java │ │ ├── MsgEntity.java │ │ ├── NewsEntity.java │ │ ├── ReviewEntity.java │ │ ├── ResponseEntity.java │ │ ├── ScoreEntity.java │ │ ├── ReplyEntity.java │ │ ├── MessageEntity.java │ │ ├── ReaderEntity.java │ │ ├── CommentEntity.java │ │ ├── PostEntity.java │ │ ├── UserEntity.java │ │ ├── ChapterEntity.java │ │ └── NovelEntity.java │ │ ├── controller │ │ ├── Format │ │ │ ├── IndexLoginFormat.java │ │ │ ├── IndexRecordFormat.java │ │ │ └── IndexRegisterFormat.java │ │ ├── NewsController.java │ │ ├── ReviewController.java │ │ ├── RecordController.java │ │ ├── ExceptionController.java │ │ ├── MessageController.java │ │ ├── ChapterController.java │ │ ├── PostController.java │ │ ├── AuthorController.java │ │ ├── BookCaseController.java │ │ ├── UserController.java │ │ └── NovelController.java │ │ ├── service │ │ ├── NewsService.java │ │ ├── ReplyService.java │ │ ├── ReviewService.java │ │ ├── MessageService.java │ │ ├── RecordService.java │ │ ├── ScoreService.java │ │ ├── UserService.java │ │ ├── PostService.java │ │ ├── ChapterService.java │ │ ├── BookCaseService.java │ │ ├── RedisService.java │ │ └── NovelService.java │ │ ├── util │ │ ├── JWTUtil.java │ │ └── SmsUtil.java │ │ └── config │ │ └── ShiroConfig.java └── test │ └── java │ └── com │ └── riyeyuedu │ └── ReaderApplicationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bbsyaya/reader/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bbsyaya/reader/HEAD/src/main/resources/application.properties -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/ReaderApplication.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ReaderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ReaderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/riyeyuedu/ReaderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ReaderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/NewsDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.NewsEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Repository 10 | public class NewsDao { 11 | public List getNews(SqlSession sqlSession, Integer flag) { 12 | return sqlSession.selectList("news.getNews", flag); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/security/JWToken.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.security; 2 | 3 | import org.apache.shiro.authc.AuthenticationToken; 4 | 5 | public class JWToken implements AuthenticationToken { 6 | private String token; 7 | 8 | public JWToken(String token) { 9 | this.token = token; 10 | } 11 | 12 | @Override 13 | public Object getPrincipal() { 14 | return token; 15 | } 16 | 17 | @Override 18 | public Object getCredentials() { 19 | return token; 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/LabelEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class LabelEntity { 4 | private Integer lid; 5 | private String labelName; 6 | 7 | public Integer getLid() { 8 | return lid; 9 | } 10 | 11 | public void setLid(Integer lid) { 12 | this.lid = lid; 13 | } 14 | 15 | public String getLabelName() { 16 | return labelName; 17 | } 18 | 19 | public void setLabelNameName(String labelName) { 20 | this.labelName = labelName; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/Format/IndexLoginFormat.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller.Format; 2 | 3 | public class IndexLoginFormat { 4 | 5 | private String username; 6 | 7 | private String password; 8 | 9 | public String getUsername() { 10 | return username; 11 | } 12 | 13 | public void setUsername(String username) { 14 | this.username = username; 15 | } 16 | 17 | public String getPassword() { 18 | return password; 19 | } 20 | 21 | public void setPassword(String password) { 22 | this.password = password; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/AttitudeEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class AttitudeEntity { 4 | private int uid; 5 | 6 | private Long pid; 7 | 8 | private int state; 9 | 10 | public int getUid() { 11 | return uid; 12 | } 13 | 14 | public void setUid(int uid) { 15 | this.uid = uid; 16 | } 17 | 18 | public Long getPid() { 19 | return pid; 20 | } 21 | 22 | public void setPid(Long pid) { 23 | this.pid = pid; 24 | } 25 | 26 | public int getState() { 27 | return state; 28 | } 29 | 30 | public void setState(int state) { 31 | this.state = state; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/BookCaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class BookCaseEntity { 4 | private Long bid; 5 | 6 | private int uid; 7 | 8 | private String type; 9 | 10 | public Long getBid() { 11 | return bid; 12 | } 13 | 14 | public void setBid(Long bid) { 15 | this.bid = bid; 16 | } 17 | 18 | public int getUid() { 19 | return uid; 20 | } 21 | 22 | public void setUid(int uid) { 23 | this.uid = uid; 24 | } 25 | 26 | public String getType() { 27 | return type; 28 | } 29 | 30 | public void setType(String type) { 31 | this.type = type; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/ReplyDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.ReplyEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Repository 11 | public class ReplyDao { 12 | public Boolean addReply(SqlSession sqlSession, ReplyEntity replyEntity) { 13 | int addNum = sqlSession.insert("reply.insertReply", replyEntity); 14 | return addNum == 1; 15 | } 16 | 17 | public List> getReplyByPid(SqlSession sqlSession, Long pid) { 18 | return sqlSession.selectList("reply.getReplyByPid", pid); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/mapping/newsMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/RecordEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class RecordEntity { 4 | private int uid; 5 | 6 | private Long cid; 7 | 8 | private Long nid; 9 | 10 | private Long time; 11 | 12 | public int getUid() { 13 | return uid; 14 | } 15 | 16 | public void setUid(int uid) { 17 | this.uid = uid; 18 | } 19 | 20 | public Long getCid() { 21 | return cid; 22 | } 23 | 24 | public void setCid(Long cid) { 25 | this.cid = cid; 26 | } 27 | 28 | public Long getNid() { 29 | return nid; 30 | } 31 | 32 | public void setNid(Long nid) { 33 | this.nid = nid; 34 | } 35 | 36 | public Long getTime() { 37 | return time; 38 | } 39 | 40 | public void setTime(Long time) { 41 | this.time = time; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/NewsService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.NewsDao; 4 | import com.riyeyuedu.entity.NewsEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class NewsService { 13 | private NewsDao newsDao; 14 | 15 | private SqlSession sqlSession; 16 | 17 | @Autowired 18 | public void setNewsDao(NewsDao newsDao) { 19 | this.newsDao = newsDao; 20 | } 21 | 22 | @Autowired 23 | public void setSqlSession(SqlSession sqlSession) { 24 | this.sqlSession = sqlSession; 25 | } 26 | 27 | public List getNews(Integer flag) { 28 | return newsDao.getNews(sqlSession, flag); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/Format/IndexRecordFormat.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller.Format; 2 | 3 | public class IndexRecordFormat { 4 | private int uid; 5 | 6 | private Long cid; 7 | 8 | private Long nid; 9 | 10 | private Long time; 11 | 12 | public int getUid() { 13 | return uid; 14 | } 15 | 16 | public void setUid(int uid) { 17 | this.uid = uid; 18 | } 19 | 20 | public Long getCid() { 21 | return cid; 22 | } 23 | 24 | public void setCid(Long cid) { 25 | this.cid = cid; 26 | } 27 | 28 | public Long getTime() { 29 | return time; 30 | } 31 | 32 | public void setTime(Long time) { 33 | this.time = time; 34 | } 35 | 36 | public Long getNid() { 37 | return nid; 38 | } 39 | 40 | public void setNid(Long nid) { 41 | this.nid = nid; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/ReviewDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.ReviewEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Repository 11 | public class ReviewDao { 12 | public Boolean addReview(SqlSession sqlSession, ReviewEntity reviewEntity) { 13 | int addNum = sqlSession.insert("review.insertReview", reviewEntity); 14 | return addNum == 1; 15 | } 16 | 17 | public List> getReviewByRid(SqlSession sqlSession, int rid) { 18 | return sqlSession.selectList("review.getReviewByRid", rid); 19 | } 20 | 21 | public Boolean deleteReview(SqlSession sqlSession, Long id) { 22 | int deleteNum = sqlSession.delete("review.deleteReview", id); 23 | return deleteNum == 1; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/MsgEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class MsgEntity { 4 | private String title; 5 | private String content; 6 | private String extraInfo; 7 | 8 | public MsgEntity() { 9 | } 10 | 11 | public String getTitle() { 12 | return title; 13 | } 14 | 15 | public void setTitle(String title) { 16 | this.title = title; 17 | } 18 | 19 | public String getContent() { 20 | return content; 21 | } 22 | 23 | public void setContent(String content) { 24 | this.content = content; 25 | } 26 | 27 | public String getExtraInfo() { 28 | return extraInfo; 29 | } 30 | 31 | public void setExtraInfo(String extraInfo) { 32 | this.extraInfo = extraInfo; 33 | } 34 | 35 | public MsgEntity(String title, String content, String extraInfo) { 36 | this.title = title; 37 | this.content = content; 38 | this.extraInfo = extraInfo; 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/ReplyService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.ReplyDao; 4 | import com.riyeyuedu.entity.ReplyEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @Service 13 | public class ReplyService { 14 | private ReplyDao replyDao; 15 | 16 | private SqlSession sqlSession; 17 | 18 | @Autowired 19 | public void setReplyDao(ReplyDao replyDao) { 20 | this.replyDao = replyDao; 21 | } 22 | 23 | @Autowired 24 | public void setSqlSession(SqlSession sqlSession) { 25 | this.sqlSession = sqlSession; 26 | } 27 | 28 | public Boolean addReply(ReplyEntity replyEntity) { 29 | return replyDao.addReply(sqlSession, replyEntity); 30 | } 31 | 32 | public List> getReplyByPid(Long pid) { 33 | return replyDao.getReplyByPid(sqlSession, pid); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/NewsEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class NewsEntity { 4 | private Integer id; 5 | 6 | private String title; 7 | 8 | private String content; 9 | 10 | private Long time; 11 | 12 | private Integer flag; 13 | 14 | public Integer getId() { 15 | return id; 16 | } 17 | 18 | public void setId(Integer id) { 19 | this.id = id; 20 | } 21 | 22 | public String getTitle() { 23 | return title; 24 | } 25 | 26 | public void setTitle(String title) { 27 | this.title = title; 28 | } 29 | 30 | public String getContent() { 31 | return content; 32 | } 33 | 34 | public void setContent(String content) { 35 | this.content = content; 36 | } 37 | 38 | public Long getTime() { 39 | return time; 40 | } 41 | 42 | public void setTime(Long time) { 43 | this.time = time; 44 | } 45 | 46 | public Integer getFlag() { 47 | return flag; 48 | } 49 | 50 | public void setFlag(Integer flag) { 51 | this.flag = flag; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/ReviewEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class ReviewEntity { 4 | private Long id; 5 | 6 | private Integer rid; 7 | 8 | private Long nid; 9 | 10 | private String content; 11 | 12 | private Long time; 13 | 14 | private Integer likeNum; 15 | 16 | public Long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | 24 | public Integer getRid() { 25 | return rid; 26 | } 27 | 28 | public void setRid(Integer rid) { 29 | this.rid = rid; 30 | } 31 | 32 | public Long getNid() { 33 | return nid; 34 | } 35 | 36 | public void setNid(Long nid) { 37 | this.nid = nid; 38 | } 39 | 40 | public String getContent() { 41 | return content; 42 | } 43 | 44 | public void setContent(String content) { 45 | this.content = content; 46 | } 47 | 48 | public Long getTime() { 49 | return time; 50 | } 51 | 52 | public void setTime(Long time) { 53 | this.time = time; 54 | } 55 | 56 | public Integer getLikeNum() { 57 | return likeNum; 58 | } 59 | 60 | public void setLikeNum(Integer likeNum) { 61 | this.likeNum = likeNum; 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/ReviewService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.ReviewDao; 4 | import com.riyeyuedu.entity.ReviewEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @Service 13 | public class ReviewService { 14 | private SqlSession sqlSession; 15 | 16 | private ReviewDao reviewDao; 17 | 18 | @Autowired 19 | public void setSqlSession(SqlSession sqlSession) { 20 | this.sqlSession = sqlSession; 21 | } 22 | 23 | @Autowired 24 | public void setReviewDao(ReviewDao reviewDao) { 25 | this.reviewDao = reviewDao; 26 | } 27 | 28 | public Boolean addReview(ReviewEntity reviewEntity) { 29 | return reviewDao.addReview(sqlSession, reviewEntity); 30 | } 31 | 32 | public List> getReviewByRid(int rid) { 33 | return reviewDao.getReviewByRid(sqlSession, rid); 34 | } 35 | 36 | public Boolean deleteReview(Long id) { 37 | return reviewDao.deleteReview(sqlSession, id); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/NewsController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import com.riyeyuedu.entity.ResponseEntity; 6 | import com.riyeyuedu.service.NewsService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | @RestController 16 | public class NewsController { 17 | private NewsService newsService; 18 | 19 | @Autowired 20 | public void setNewsService(NewsService newsService) { 21 | this.newsService = newsService; 22 | } 23 | 24 | @RequestMapping(value = "/authorNews") 25 | public ResponseEntity getNews(@RequestParam("page") int page) { 26 | Page pager = PageHelper.startPage(page, 10); 27 | Map map = new HashMap<>(); 28 | map.put("newsList", newsService.getNews(0)); 29 | map.put("total", pager.getTotal()); 30 | return new ResponseEntity(map); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/ResponseEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class ResponseEntity { 4 | // http 状态码 5 | private int code; 6 | 7 | // 返回信息 8 | private String msg; 9 | 10 | // 返回的数据 11 | private Object data; 12 | 13 | public ResponseEntity(Object data) { 14 | this(200, "success", data); 15 | } 16 | 17 | public ResponseEntity(String msg) { 18 | this(200, msg, null); 19 | } 20 | 21 | public ResponseEntity(String msg, Object data) { 22 | this(200, msg, data); 23 | } 24 | 25 | public ResponseEntity(Integer code, String msg, Object data) { 26 | this.code = code; 27 | this.msg = msg; 28 | this.data = data; 29 | } 30 | 31 | public int getCode() { 32 | return code; 33 | } 34 | 35 | public void setCode(int code) { 36 | this.code = code; 37 | } 38 | 39 | public String getMsg() { 40 | return msg; 41 | } 42 | 43 | public void setMsg(String msg) { 44 | this.msg = msg; 45 | } 46 | 47 | public Object getData() { 48 | return data; 49 | } 50 | 51 | public void setData(Object data) { 52 | this.data = data; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/Format/IndexRegisterFormat.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller.Format; 2 | 3 | public class IndexRegisterFormat { 4 | 5 | private String phone; 6 | 7 | private String code; 8 | 9 | private String username; 10 | 11 | private String password; 12 | 13 | private String checkPass; 14 | 15 | public String getPhone() { 16 | return phone; 17 | } 18 | 19 | public void setPhone(String phone) { 20 | this.phone = phone; 21 | } 22 | 23 | public String getCode() { 24 | return code; 25 | } 26 | 27 | public void setCode(String code) { 28 | this.code = code; 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public void setPassword(String password) { 36 | this.password = password; 37 | } 38 | 39 | public String getCheckPass() { 40 | return checkPass; 41 | } 42 | 43 | public void setCheckPass(String checkPass) { 44 | this.checkPass = checkPass; 45 | } 46 | 47 | public String getUsername() { 48 | return username; 49 | } 50 | 51 | public void setUsername(String username) { 52 | this.username = username; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/resources/mapping/ReplyMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO reply(pid, reply_id, content, from_uid, to_uid, time) VALUES (#{pid}, #{replyId}, #{content}, #{fromUid}, #{toUid}, #{time}) 7 | 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/ScoreEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class ScoreEntity { 4 | private int uid; 5 | 6 | private Long nid; 7 | 8 | private int score; 9 | 10 | private String content; 11 | 12 | private Long time; 13 | 14 | private Integer likeNum; 15 | 16 | public int getUid() { 17 | return uid; 18 | } 19 | 20 | public void setUid(int rid) { 21 | this.uid = uid; 22 | } 23 | 24 | public Long getNid() { 25 | return nid; 26 | } 27 | 28 | public void setNid(Long nid) { 29 | this.nid = nid; 30 | } 31 | 32 | public int getScore() { 33 | return score; 34 | } 35 | 36 | public void setScore(int score) { 37 | this.score = score; 38 | } 39 | 40 | public String getContent() { 41 | return content; 42 | } 43 | 44 | public void setContent(String content) { 45 | this.content = content; 46 | } 47 | 48 | public Long getTime() { 49 | return time; 50 | } 51 | 52 | public void setTime(Long time) { 53 | this.time = time; 54 | } 55 | 56 | public Integer getLikeNum() { 57 | return likeNum; 58 | } 59 | 60 | public void setLikeNum(Integer likeNum) { 61 | this.likeNum = likeNum; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/ReviewController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.ResponseEntity; 4 | import com.riyeyuedu.entity.ReviewEntity; 5 | import com.riyeyuedu.service.ReviewService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.Date; 10 | 11 | @RestController 12 | public class ReviewController { 13 | 14 | private ReviewService reviewService; 15 | 16 | @Autowired 17 | public void setReviewService(ReviewService reviewService) { 18 | this.reviewService = reviewService; 19 | } 20 | 21 | @RequestMapping(value = "/sendReview", method = RequestMethod.POST) 22 | @CrossOrigin 23 | public ResponseEntity sendReview(@RequestBody ReviewEntity reviewEntity) { 24 | reviewEntity.setTime(new Date().getTime()); 25 | return new ResponseEntity(reviewService.addReview(reviewEntity)); 26 | } 27 | 28 | @RequestMapping(value = "/getReview/{rid}") 29 | @CrossOrigin 30 | public ResponseEntity getReview(@PathVariable int rid) { 31 | return new ResponseEntity(reviewService.getReviewByRid(rid)); 32 | } 33 | 34 | @RequestMapping(value = "/deleteReview/{id}") 35 | @CrossOrigin 36 | public ResponseEntity deleteReview(@PathVariable Long id) { 37 | return new ResponseEntity(reviewService.deleteReview(id)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/MessageDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.MessageEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Repository 11 | public class MessageDao { 12 | 13 | public Boolean addMessage(SqlSession sqlSession, MessageEntity messageEntity) { 14 | int addNum = sqlSession.insert("message.insertMessage", messageEntity); 15 | return addNum == 1; 16 | } 17 | 18 | public List> getMessageByToId(SqlSession sqlSession, Map map) { 19 | return sqlSession.selectList("message.getMessageByToId", map); 20 | } 21 | 22 | public MessageEntity getMessageByMid(SqlSession sqlSession, Long mid) { 23 | return sqlSession.selectOne("message.getMessageByMid", mid); 24 | } 25 | 26 | public Integer getUnReadMessageNum(SqlSession sqlSession, int uid) { 27 | return sqlSession.selectOne("message.getUnReadMessageNum", uid); 28 | } 29 | 30 | public Boolean deleteMessageByMid(SqlSession sqlSession, Long mid) { 31 | int deleteNum = sqlSession.delete("message.deleteMessageByMid", mid); 32 | return deleteNum == 1; 33 | } 34 | 35 | public Boolean updateRead(SqlSession sqlSession, Long mid) { 36 | int updateNum = sqlSession.update("message.updateRead", mid); 37 | return updateNum == 1; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/RecordController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.controller.Format.IndexRecordFormat; 4 | import com.riyeyuedu.entity.RecordEntity; 5 | import com.riyeyuedu.entity.ResponseEntity; 6 | import com.riyeyuedu.service.RecordService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.Date; 11 | 12 | @RestController 13 | public class RecordController { 14 | private RecordService recordService; 15 | 16 | @Autowired 17 | public void setRecordService(RecordService recordService) { 18 | this.recordService = recordService; 19 | } 20 | 21 | @RequestMapping(value = "/user/addRecord", method = RequestMethod.POST) 22 | @CrossOrigin 23 | public ResponseEntity addRecord(@RequestBody IndexRecordFormat format) { 24 | 25 | RecordEntity recordEntity = new RecordEntity(); 26 | recordEntity.setCid(format.getCid()); 27 | recordEntity.setNid(format.getNid()); 28 | recordEntity.setUid(format.getUid()); 29 | recordEntity.setTime(new Date().getTime()); 30 | boolean result; 31 | 32 | if (recordService.getRecord(recordEntity) != null) { 33 | result = recordService.updateRecord(recordEntity); 34 | } else { 35 | result = recordService.addRecord(recordEntity); 36 | } 37 | 38 | return new ResponseEntity(200, "添加纪录成功", result); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/RecordDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.RecordEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Repository 11 | public class RecordDao { 12 | public Boolean addRecord(SqlSession sqlSession, RecordEntity record) { 13 | int insertNum = sqlSession.insert("record.insertRecord", record); 14 | return insertNum == 1; 15 | } 16 | 17 | public RecordEntity getRecord(SqlSession sqlSession, RecordEntity record) { 18 | return sqlSession.selectOne("record.getRecord", record); 19 | } 20 | 21 | public List> getAllRecordDetail(SqlSession sqlSession, int uid) { 22 | return sqlSession.selectList("record.getAllRecordDetail", uid); 23 | } 24 | 25 | public Map getRecordDetail(SqlSession sqlSession, RecordEntity recordEntity) { 26 | return sqlSession.selectOne("record.getRecordDetail", recordEntity); 27 | } 28 | 29 | public Boolean deleteRecord(SqlSession sqlSession, RecordEntity record) { 30 | int deleteNum = sqlSession.delete("record.deleteRecord", record); 31 | return deleteNum == 1; 32 | } 33 | 34 | public Boolean updateRecord(SqlSession sqlSession, RecordEntity recordEntity) { 35 | int updateNum = sqlSession.update("record.updateRecord", recordEntity); 36 | return updateNum == 1; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/ReplyEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class ReplyEntity { 4 | private Long id; 5 | 6 | private Long pid; 7 | 8 | private Long replyId; 9 | 10 | private String content; 11 | 12 | private int fromUid; 13 | 14 | private int toUid; 15 | 16 | private Long time; 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | 26 | public Long getPid() { 27 | return pid; 28 | } 29 | 30 | public void setPid(Long pid) { 31 | this.pid = pid; 32 | } 33 | 34 | public Long getReplyId() { 35 | return replyId; 36 | } 37 | 38 | public void setReplyId(Long replyId) { 39 | this.replyId = replyId; 40 | } 41 | 42 | public String getContent() { 43 | return content; 44 | } 45 | 46 | public void setContent(String content) { 47 | this.content = content; 48 | } 49 | 50 | public int getFromUid() { 51 | return fromUid; 52 | } 53 | 54 | public void setFromUid(int fromUid) { 55 | this.fromUid = fromUid; 56 | } 57 | 58 | public int getToUid() { 59 | return toUid; 60 | } 61 | 62 | public void setToUid(int toUid) { 63 | this.toUid = toUid; 64 | } 65 | 66 | public Long getTime() { 67 | return time; 68 | } 69 | 70 | public void setTime(Long time) { 71 | this.time = time; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/MessageService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.MessageDao; 4 | import com.riyeyuedu.entity.MessageEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @Service 13 | public class MessageService { 14 | private MessageDao messageDao; 15 | 16 | private SqlSession sqlSession; 17 | 18 | @Autowired 19 | public void setMessageDao(MessageDao messageDao) { 20 | this.messageDao = messageDao; 21 | } 22 | 23 | @Autowired 24 | public void setSqlSession(SqlSession sqlSession) { 25 | this.sqlSession = sqlSession; 26 | } 27 | 28 | public Boolean addMessage(MessageEntity messageEntity) { 29 | return messageDao.addMessage(sqlSession, messageEntity); 30 | } 31 | 32 | public List> getMessageByToId(Map map) { 33 | return messageDao.getMessageByToId(sqlSession, map); 34 | } 35 | 36 | public MessageEntity getMessageByMid(Long mid) { 37 | messageDao.updateRead(sqlSession, mid); 38 | return messageDao.getMessageByMid(sqlSession, mid); 39 | } 40 | 41 | public Integer getUnReadMessageNum(int uid) { 42 | return messageDao.getUnReadMessageNum(sqlSession, uid); 43 | } 44 | 45 | public Boolean deleteMessage(Long mid) { 46 | return messageDao.deleteMessageByMid(sqlSession, mid); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 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 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/RecordService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.RecordDao; 4 | import com.riyeyuedu.entity.RecordEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @Service 13 | public class RecordService { 14 | private SqlSession sqlSession; 15 | 16 | private RecordDao recordDao; 17 | 18 | public RecordService(SqlSession sqlSession) { 19 | this.sqlSession = sqlSession; 20 | } 21 | 22 | @Autowired 23 | public void setRecordDao(RecordDao recordDao) { 24 | this.recordDao = recordDao; 25 | } 26 | 27 | public Boolean addRecord(RecordEntity record) { 28 | return recordDao.addRecord(sqlSession, record); 29 | } 30 | 31 | public RecordEntity getRecord(RecordEntity record) { 32 | return recordDao.getRecord(sqlSession, record); 33 | } 34 | 35 | public List> getAllRecordDetail(int uid) { 36 | return recordDao.getAllRecordDetail(sqlSession, uid); 37 | } 38 | 39 | public Map getRecordDetail(RecordEntity recordEntity) { 40 | return recordDao.getRecordDetail(sqlSession, recordEntity); 41 | } 42 | 43 | public Boolean deleteRecord(RecordEntity record) { 44 | return recordDao.deleteRecord(sqlSession, record); 45 | } 46 | 47 | public Boolean updateRecord(RecordEntity recordEntity) { 48 | return recordDao.updateRecord(sqlSession, recordEntity); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/MessageEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class MessageEntity { 4 | private Long mid; 5 | 6 | private int type; 7 | 8 | private String title; 9 | 10 | private String content; 11 | 12 | private Long time; 13 | 14 | private int isRead; 15 | 16 | private int fromId; 17 | 18 | private int toId; 19 | 20 | public Long getMid() { 21 | return mid; 22 | } 23 | 24 | public void setMid(Long mid) { 25 | this.mid = mid; 26 | } 27 | 28 | public int getType() { 29 | return type; 30 | } 31 | 32 | public void setType(int type) { 33 | this.type = type; 34 | } 35 | 36 | public String getTitle() { 37 | return title; 38 | } 39 | 40 | public void setTitle(String title) { 41 | this.title = title; 42 | } 43 | 44 | public String getContent() { 45 | return content; 46 | } 47 | 48 | public void setContent(String content) { 49 | this.content = content; 50 | } 51 | 52 | public Long getTime() { 53 | return time; 54 | } 55 | 56 | public void setTime(Long time) { 57 | this.time = time; 58 | } 59 | 60 | public int getIsRead() { 61 | return isRead; 62 | } 63 | 64 | public void setIsRead(int isRead) { 65 | this.isRead = isRead; 66 | } 67 | 68 | public int getFromId() { 69 | return fromId; 70 | } 71 | 72 | public void setFromId(int fromId) { 73 | this.fromId = fromId; 74 | } 75 | 76 | public int getToId() { 77 | return toId; 78 | } 79 | 80 | public void setToId(int toId) { 81 | this.toId = toId; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/resources/mapping/ReviewMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO review (rid, nid, content, time, like_num) VALUES (#{rid}, #{nid}, #{content}, #{time}, #{likeNum}) 7 | 8 | 9 | 19 | 20 | 21 | DELETE FROM review WHERE id = #{id} 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/ScoreDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.ScoreEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Repository 11 | public class ScoreDao { 12 | public Boolean addScore(SqlSession sqlSession, ScoreEntity scoreEntity) { 13 | int addNum = sqlSession.insert("score.insertScore", scoreEntity); 14 | return addNum == 1; 15 | } 16 | 17 | public Boolean updateScore(SqlSession sqlSession, ScoreEntity scoreEntity) { 18 | int updateNum = sqlSession.update("score.updateScore", scoreEntity); 19 | return updateNum == 1; 20 | } 21 | 22 | public ScoreEntity getScore(SqlSession sqlSession, ScoreEntity scoreEntity) { 23 | return sqlSession.selectOne("score.getScore", scoreEntity); 24 | } 25 | 26 | public Integer getScoreByUid(SqlSession sqlSession, ScoreEntity scoreEntity) { 27 | return sqlSession.selectOne("score.getScoreByUid", scoreEntity); 28 | } 29 | 30 | public List> getScoresByUid(SqlSession sqlSession, int uid) { 31 | return sqlSession.selectList("score.getScoresByUid", uid); 32 | } 33 | 34 | public List> getScoreByNid(SqlSession sqlSession, Long nid) { 35 | return sqlSession.selectList("score.getScoreByNid", nid); 36 | } 37 | 38 | public Integer getScoreNumByNid(SqlSession sqlSession, Long nid) { 39 | return sqlSession.selectOne("score.getScoreNumByNid", nid); 40 | } 41 | 42 | public Double getAvgScoreByNid(SqlSession sqlSession, Long nid) { 43 | return sqlSession.selectOne("score.getAvgScoreByNid", nid); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/ExceptionController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.ResponseEntity; 4 | import org.apache.shiro.ShiroException; 5 | import org.apache.shiro.authz.UnauthorizedException; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.ResponseStatus; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | 13 | @RestControllerAdvice 14 | public class ExceptionController { 15 | 16 | // 捕捉shiro的异常 17 | @ResponseStatus(HttpStatus.UNAUTHORIZED) 18 | @ExceptionHandler(ShiroException.class) 19 | public ResponseEntity handle401(ShiroException e) { 20 | return new ResponseEntity(401, e.getMessage(), null); 21 | } 22 | 23 | // 捕捉UnauthorizedException 24 | @ResponseStatus(HttpStatus.UNAUTHORIZED) 25 | @ExceptionHandler(UnauthorizedException.class) 26 | public ResponseEntity handle401() { 27 | return new ResponseEntity(401, "Unauthorized", null); 28 | } 29 | 30 | // 捕捉其他所有异常 31 | @ExceptionHandler(Exception.class) 32 | @ResponseStatus(HttpStatus.BAD_REQUEST) 33 | public ResponseEntity globalException(HttpServletRequest request, Throwable ex) { 34 | return new ResponseEntity(getStatus(request).value(), ex.getMessage(), null); 35 | } 36 | 37 | private HttpStatus getStatus(HttpServletRequest request) { 38 | Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); 39 | if (statusCode == null) { 40 | return HttpStatus.INTERNAL_SERVER_ERROR; 41 | } 42 | return HttpStatus.valueOf(statusCode); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/resources/mapping/RecordMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO record (uid, cid, nid, time) VALUES (#{uid}, #{cid}, #{nid}, #{time}) 7 | 8 | 9 | 12 | 13 | 18 | 19 | 24 | 25 | 26 | DELETE FROM record WHERE cid = #{cid} AND uid = #{uid} 27 | 28 | 29 | 30 | UPDATE record SET cid = #{cid}, time = #{time} WHERE uid = #{uid} AND nid = #{nid} 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/ReaderEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class ReaderEntity { 4 | private int rid; 5 | 6 | private String readerName; 7 | 8 | private String password; 9 | 10 | private String portrait; 11 | 12 | private String phone; 13 | 14 | private String sex; 15 | 16 | private Long birthday; 17 | 18 | private String info; 19 | 20 | public String getPhone() { 21 | return phone; 22 | } 23 | 24 | public void setPhone(String phone) { 25 | this.phone = phone; 26 | } 27 | 28 | public int getRid() { 29 | return rid; 30 | } 31 | 32 | public void setRid(int rid) { 33 | this.rid = rid; 34 | } 35 | 36 | public String getReaderName() { 37 | return readerName; 38 | } 39 | 40 | public void setReaderName(String readerName) { 41 | this.readerName = readerName; 42 | } 43 | 44 | public String getPassword() { 45 | return password; 46 | } 47 | 48 | public void setPassword(String password) { 49 | this.password = password; 50 | } 51 | 52 | public String getPortrait() { 53 | return portrait; 54 | } 55 | 56 | public void setPortrait(String portrait) { 57 | this.portrait = portrait; 58 | } 59 | 60 | public String getSex() { 61 | return sex; 62 | } 63 | 64 | public void setSex(String sex) { 65 | this.sex = sex; 66 | } 67 | 68 | public Long getBirthday() { 69 | return birthday; 70 | } 71 | 72 | public void setBirthday(Long birthday) { 73 | this.birthday = birthday; 74 | } 75 | 76 | public String getInfo() { 77 | return info; 78 | } 79 | 80 | public void setInfo(String info) { 81 | this.info = info; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/ScoreService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.ScoreDao; 4 | import com.riyeyuedu.entity.ScoreEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @Service 13 | public class ScoreService { 14 | private SqlSession sqlSession; 15 | 16 | private ScoreDao scoreDao; 17 | 18 | @Autowired 19 | public void setSqlSession(SqlSession sqlSession) { 20 | this.sqlSession = sqlSession; 21 | } 22 | 23 | @Autowired 24 | public void setScoreDao(ScoreDao scoreDao) { 25 | this.scoreDao = scoreDao; 26 | } 27 | 28 | public Boolean addScore(ScoreEntity scoreEntity) { 29 | return scoreDao.addScore(sqlSession, scoreEntity); 30 | } 31 | 32 | public Boolean updateScore(ScoreEntity scoreEntity) { 33 | return scoreDao.updateScore(sqlSession, scoreEntity); 34 | } 35 | 36 | public ScoreEntity getScore(ScoreEntity scoreEntity) { 37 | return scoreDao.getScore(sqlSession, scoreEntity); 38 | } 39 | 40 | public Integer getScoreByUid(ScoreEntity scoreEntity) { return scoreDao.getScoreByUid(sqlSession, scoreEntity); } 41 | 42 | public List> getScoresByUid(int uid) { 43 | return scoreDao.getScoresByUid(sqlSession, uid); 44 | } 45 | 46 | public Integer getScoreNumByNid(Long nid) { 47 | return scoreDao.getScoreNumByNid(sqlSession, nid); 48 | } 49 | 50 | public Double getAvgScoreByNid( Long nid) { 51 | return scoreDao.getAvgScoreByNid(sqlSession, nid); 52 | } 53 | 54 | public List> getScoreByNid(Long nid) { return scoreDao.getScoreByNid(sqlSession, nid); } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/CommentEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class CommentEntity { 4 | private Long cid; 5 | 6 | private int ownerReaderId; 7 | 8 | private int targetReaderId; 9 | 10 | private String content; 11 | 12 | private int likeNum; 13 | 14 | private String createTime; 15 | 16 | private Long parentId; 17 | 18 | private int flag; 19 | 20 | public Long getCid() { 21 | return cid; 22 | } 23 | 24 | public void setCid(Long cid) { 25 | this.cid = cid; 26 | } 27 | 28 | public String getContent() { 29 | return content; 30 | } 31 | 32 | public void setContent(String content) { 33 | this.content = content; 34 | } 35 | 36 | public Long getParentId() { 37 | return parentId; 38 | } 39 | 40 | public void setParentId(Long parentId) { 41 | this.parentId = parentId; 42 | } 43 | 44 | public int getOwnerReaderId() { 45 | return ownerReaderId; 46 | } 47 | 48 | public void setOwnerReaderId(int ownerReaderId) { 49 | this.ownerReaderId = ownerReaderId; 50 | } 51 | 52 | public int getTargetReaderId() { 53 | return targetReaderId; 54 | } 55 | 56 | public void setTargetReaderId(int targetReaderId) { 57 | this.targetReaderId = targetReaderId; 58 | } 59 | 60 | public int getLikeNum() { 61 | return likeNum; 62 | } 63 | 64 | public void setLikeNum(int likeNum) { 65 | this.likeNum = likeNum; 66 | } 67 | 68 | public String getCreateTime() { 69 | return createTime; 70 | } 71 | 72 | public void setCreateTime(String createTime) { 73 | this.createTime = createTime; 74 | } 75 | 76 | public int getFlag() { 77 | return flag; 78 | } 79 | 80 | public void setFlag(int flag) { 81 | this.flag = flag; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.UserEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public class UserDao { 9 | public Boolean addUser(SqlSession sqlSession, UserEntity userEntity) { 10 | int insertNum = sqlSession.insert("user.insertUser", userEntity); 11 | return insertNum == 1; 12 | } 13 | 14 | public Boolean changePassword(SqlSession sqlSession, UserEntity userEntity) { 15 | int updateNum = sqlSession.update("user.updatePassword", userEntity); 16 | return updateNum == 1; 17 | } 18 | 19 | public String getPortraitByUid(SqlSession sqlSession, int uid) { 20 | return sqlSession.selectOne("user.getPortraitByUid", uid); 21 | } 22 | 23 | public UserEntity getInfoByUid(SqlSession sqlSession, int uid) { 24 | return sqlSession.selectOne("user.getInfoByUid", uid); 25 | } 26 | 27 | public UserEntity getUserByPhone(SqlSession sqlSession, String phone) { 28 | return sqlSession.selectOne("user.getUserByPhone", phone); 29 | } 30 | 31 | public UserEntity getUserByUsername(SqlSession sqlSession, String username) { 32 | return sqlSession.selectOne("user.getUserByUsername", username); 33 | } 34 | 35 | public UserEntity getReaderByReaderName(SqlSession sqlSession, String username) { 36 | return sqlSession.selectOne("user.getUserByName", username); 37 | } 38 | 39 | public Boolean updateAvatar(SqlSession sqlSession, UserEntity userEntity) { 40 | int updateNum = sqlSession.update("user.updateAvatar", userEntity); 41 | return updateNum == 1; 42 | } 43 | 44 | public Boolean updateInfo(SqlSession sqlSession, UserEntity userEntity) { 45 | int updateNum = sqlSession.update("user.updateInfo", userEntity); 46 | return updateNum == 1; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.UserDao; 4 | import com.riyeyuedu.entity.UserEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | public class UserService { 11 | private UserDao userDao; 12 | 13 | private SqlSession sqlSession; 14 | 15 | @Autowired 16 | public void setUserDao(UserDao userDao) { 17 | this.userDao = userDao; 18 | } 19 | 20 | @Autowired 21 | public void setSqlSession(SqlSession sqlSession) { 22 | this.sqlSession = sqlSession; 23 | } 24 | 25 | public Boolean register(UserEntity userEntity) { 26 | return userDao.addUser(sqlSession, userEntity); 27 | } 28 | 29 | public Boolean changePassword(UserEntity userEntity) { 30 | return userDao.changePassword(sqlSession, userEntity); 31 | } 32 | 33 | public String getPortraitByUid(int uid) { 34 | return userDao.getPortraitByUid(sqlSession, uid); 35 | } 36 | 37 | public UserEntity getInfoByUid(int uid) { 38 | return userDao.getInfoByUid(sqlSession, uid); 39 | } 40 | 41 | public UserEntity getUserByPhone(String phone) { 42 | return userDao.getUserByPhone(sqlSession, phone); 43 | } 44 | 45 | public UserEntity getUserByUsername(String username) { 46 | return userDao.getUserByUsername(sqlSession, username); 47 | } 48 | 49 | public UserEntity getReaderByName(String name) { 50 | return userDao.getReaderByReaderName(sqlSession, name); 51 | } 52 | 53 | public Boolean updateAvatar(UserEntity userEntity) { 54 | return userDao.updateAvatar(sqlSession, userEntity); 55 | } 56 | 57 | public Boolean updateInfo(UserEntity userEntity) { 58 | return userDao.updateInfo(sqlSession, userEntity); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/PostEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class PostEntity { 4 | private Long pid; 5 | 6 | private Long nid; 7 | 8 | private int uid; 9 | 10 | private String theme; 11 | 12 | private String content; 13 | 14 | private int likeNum; 15 | 16 | private Long updateTime; 17 | 18 | private int level; 19 | 20 | private int replyNum; 21 | 22 | public Long getPid() { 23 | return pid; 24 | } 25 | 26 | public void setPid(Long pid) { 27 | this.pid = pid; 28 | } 29 | 30 | public Long getNid() { 31 | return nid; 32 | } 33 | 34 | public void setNid(Long nid) { 35 | this.nid = nid; 36 | } 37 | 38 | public int getUid() { 39 | return uid; 40 | } 41 | 42 | public void setUid(int uid) { 43 | this.uid = uid; 44 | } 45 | 46 | public String getTheme() { 47 | return theme; 48 | } 49 | 50 | public void setTheme(String theme) { 51 | this.theme = theme; 52 | } 53 | 54 | public String getContent() { 55 | return content; 56 | } 57 | 58 | public void setContent(String content) { 59 | this.content = content; 60 | } 61 | 62 | public int getLikeNum() { 63 | return likeNum; 64 | } 65 | 66 | public void setLikeNum(int likeNum) { 67 | this.likeNum = likeNum; 68 | } 69 | 70 | public Long getUpdateTime() { 71 | return updateTime; 72 | } 73 | 74 | public void setUpdateTime(Long updateTime) { 75 | this.updateTime = updateTime; 76 | } 77 | 78 | public int getLevel() { 79 | return level; 80 | } 81 | 82 | public void setLevel(int level) { 83 | this.level = level; 84 | } 85 | 86 | public int getReplyNum() { 87 | return replyNum; 88 | } 89 | 90 | public void setReplyNum(int replyNum) { 91 | this.replyNum = replyNum; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/UserEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class UserEntity { 4 | private Integer uid; 5 | 6 | private String username; 7 | 8 | private String password; 9 | 10 | private String phone; 11 | 12 | private Integer sex; 13 | 14 | private Long birthday; 15 | 16 | private String info; 17 | 18 | private String portrait; 19 | 20 | private Integer permission; 21 | 22 | public Integer getUid() { 23 | return uid; 24 | } 25 | 26 | public void setUid(Integer uid) { 27 | this.uid = uid; 28 | } 29 | 30 | public String getUsername() { 31 | return username; 32 | } 33 | 34 | public void setUsername(String username) { 35 | this.username = username; 36 | } 37 | 38 | public String getPassword() { 39 | return password; 40 | } 41 | 42 | public void setPassword(String password) { 43 | this.password = password; 44 | } 45 | 46 | public String getPhone() { 47 | return phone; 48 | } 49 | 50 | public void setPhone(String phone) { 51 | this.phone = phone; 52 | } 53 | 54 | public Integer getSex() { 55 | return sex; 56 | } 57 | 58 | public void setSex(Integer sex) { 59 | this.sex = sex; 60 | } 61 | 62 | public Long getBirthday() { 63 | return birthday; 64 | } 65 | 66 | public void setBirthday(Long birthday) { 67 | this.birthday = birthday; 68 | } 69 | 70 | public String getInfo() { 71 | return info; 72 | } 73 | 74 | public void setInfo(String info) { 75 | this.info = info; 76 | } 77 | 78 | public String getPortrait() { 79 | return portrait; 80 | } 81 | 82 | public void setPortrait(String portrait) { 83 | this.portrait = portrait; 84 | } 85 | 86 | public Integer getPermission() { 87 | return permission; 88 | } 89 | 90 | public void setPermission(Integer permission) { 91 | this.permission = permission; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/resources/mapping/MessageMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO message (type, title, content, time, is_read, from_id, to_id) 7 | VALUES (#{type}, #{title}, #{content}, #{time}, #{isRead}, #{fromId}, #{toId}) 8 | 9 | 10 | 16 | 17 | 20 | 21 | 24 | 25 | 26 | DELETE FROM message WHERE mid = #{mid} 27 | 28 | 29 | 30 | UPDATE message SET is_read = 1 WHERE mid = #{mid} 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/ChapterEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class ChapterEntity { 4 | private Long cid; 5 | 6 | private Long nid; 7 | 8 | private String chapterName; 9 | 10 | private Long createTime; 11 | 12 | private Integer wordNum; 13 | 14 | private String draft; 15 | 16 | private String content; 17 | 18 | private int allow; 19 | 20 | private int isDraft; 21 | 22 | public Long getCid() { 23 | return cid; 24 | } 25 | 26 | public void setCid(Long cid) { 27 | this.cid = cid; 28 | } 29 | 30 | public Long getNid() { 31 | return nid; 32 | } 33 | 34 | public void setNid(Long nid) { 35 | this.nid = nid; 36 | } 37 | 38 | public String getChapterName() { 39 | return chapterName; 40 | } 41 | 42 | public void setChapterName(String chapterName) { 43 | this.chapterName = chapterName == null ? null : chapterName.trim(); 44 | } 45 | 46 | public Long getCreateTime() { 47 | return createTime; 48 | } 49 | 50 | public void setCreateTime(Long createTime) { 51 | this.createTime = createTime; 52 | } 53 | 54 | public Integer getWordNum() { 55 | return wordNum; 56 | } 57 | 58 | public void setWordNum(Integer wordNum) { 59 | this.wordNum = wordNum; 60 | } 61 | 62 | public String getDraft() { 63 | return draft; 64 | } 65 | 66 | public void setDraft(String draft) { 67 | this.draft = draft; 68 | } 69 | 70 | public String getContent() { 71 | return content; 72 | } 73 | 74 | public void setContent(String content) { 75 | this.content = content == null ? null : content.trim(); 76 | } 77 | 78 | public int getAllow() { 79 | return allow; 80 | } 81 | 82 | public void setAllow(int allow) { 83 | this.allow = allow; 84 | } 85 | 86 | public int getIsDraft() { 87 | return isDraft; 88 | } 89 | 90 | public void setIsDraft(int isDraft) { 91 | this.isDraft = isDraft; 92 | } 93 | } -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/PostService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.PostDao; 4 | import com.riyeyuedu.entity.AttitudeEntity; 5 | import com.riyeyuedu.entity.PostEntity; 6 | import org.apache.ibatis.session.SqlSession; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | @Service 14 | public class PostService { 15 | private SqlSession sqlSession; 16 | 17 | private PostDao postDao; 18 | 19 | public PostService(SqlSession sqlSession) { 20 | this.sqlSession = sqlSession; 21 | } 22 | 23 | @Autowired 24 | public void setPostDao(PostDao postDao) { 25 | this.postDao = postDao; 26 | } 27 | 28 | public Boolean addPost(PostEntity post) { 29 | return postDao.addPost(sqlSession, post); 30 | } 31 | 32 | public List> getPostByNid(Long nid) { 33 | return postDao.getPostByNid(sqlSession, nid); 34 | } 35 | 36 | public Map getPostByPid(Long pid) { 37 | return postDao.getPostByPid(sqlSession, pid); 38 | } 39 | 40 | public Integer getPostNumByNid(Long nid) { 41 | return postDao.getPostNumByNid(sqlSession, nid); 42 | } 43 | 44 | public Boolean addCommentNum(Long pid) { 45 | return postDao.addCommentNum(sqlSession, pid); 46 | } 47 | 48 | public Boolean reduceCommentNum(Long pid) { 49 | return postDao.reduceCommentNUm(sqlSession, pid); 50 | } 51 | 52 | public Boolean addLikeNum(Long pid) { 53 | return postDao.addLikeNum(sqlSession, pid); 54 | } 55 | 56 | public Boolean reduceLikeNum(Long pid) { 57 | return postDao.reduceLikeNum(sqlSession, pid); 58 | } 59 | 60 | public Boolean toAttitude(AttitudeEntity attitudeEntity) { 61 | if (postDao.isAttitude(sqlSession, attitudeEntity) != 0) { 62 | return postDao.updateAttitude(sqlSession, attitudeEntity); 63 | } else { 64 | return postDao.addAttitude(sqlSession, attitudeEntity); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/MessageController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.MessageEntity; 4 | import com.riyeyuedu.entity.ResponseEntity; 5 | import com.riyeyuedu.service.MessageService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.Date; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | @RestController 14 | public class MessageController { 15 | private MessageService messageService; 16 | 17 | @Autowired 18 | public void setMessageService(MessageService messageService) { 19 | this.messageService = messageService; 20 | } 21 | 22 | @RequestMapping(value = "/addMessage", method = RequestMethod.POST) 23 | @CrossOrigin 24 | public ResponseEntity addMessage(@RequestBody MessageEntity messageEntity) { 25 | messageEntity.setTime(new Date().getTime()); 26 | messageEntity.setIsRead(0); 27 | return new ResponseEntity(messageService.addMessage(messageEntity)); 28 | } 29 | 30 | @RequestMapping(value = "/message/{uid}/{type}") 31 | @CrossOrigin 32 | public ResponseEntity getMessageByUid(@PathVariable int uid, @PathVariable int type) { 33 | Map map = new HashMap<>(); 34 | map.put("uid", uid); 35 | map.put("type", type); 36 | return new ResponseEntity(messageService.getMessageByToId(map)); 37 | } 38 | 39 | @RequestMapping(value = "/message/{mid}") 40 | @CrossOrigin 41 | public ResponseEntity getMessageByMid(@PathVariable Long mid) { 42 | return new ResponseEntity(messageService.getMessageByMid(mid)); 43 | } 44 | 45 | @RequestMapping(value = "/message/delete/{mid}") 46 | @CrossOrigin 47 | public ResponseEntity deleteMessage(@PathVariable Long mid) { 48 | return new ResponseEntity(messageService.deleteMessage(mid)); 49 | } 50 | 51 | @RequestMapping(value = "/unReadMessageNum/{uid}") 52 | @CrossOrigin 53 | public ResponseEntity getUnReadMessageNum(@PathVariable int uid) { 54 | return new ResponseEntity(messageService.getUnReadMessageNum(uid)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/util/JWTUtil.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.util; 2 | 3 | import com.auth0.jwt.JWT; 4 | import com.auth0.jwt.JWTVerifier; 5 | import com.auth0.jwt.algorithms.Algorithm; 6 | import com.auth0.jwt.exceptions.JWTDecodeException; 7 | import com.auth0.jwt.interfaces.DecodedJWT; 8 | 9 | import java.io.UnsupportedEncodingException; 10 | import java.util.Date; 11 | 12 | public class JWTUtil { 13 | // 过期时间5分钟 14 | private static final long EXPIRE_TIME = 5*60*1000; 15 | 16 | /** 17 | * 校验token是否正确 18 | * @param token 密钥 19 | * @param secret 用户的密码 20 | * @return 是否正确 21 | */ 22 | public static boolean verify(String token, String username, String secret) { 23 | try { 24 | Algorithm algorithm = Algorithm.HMAC256(secret); 25 | JWTVerifier verifier = JWT.require(algorithm) 26 | .withClaim("username", username) 27 | .build(); 28 | DecodedJWT jwt = verifier.verify(token); 29 | return true; 30 | } catch (Exception exception) { 31 | return false; 32 | } 33 | } 34 | 35 | /** 36 | * 获得token中的信息无需secret解密也能获得 37 | * @return token中包含的用户名 38 | */ 39 | public static String getUsername(String token) { 40 | try { 41 | DecodedJWT jwt = JWT.decode(token); 42 | return jwt.getClaim("username").asString(); 43 | } catch (JWTDecodeException e) { 44 | return null; 45 | } 46 | } 47 | 48 | /** 49 | * 生成签名,5min后过期 50 | * @param username 用户名 51 | * @param secret 用户的密码 52 | * @return 加密的token 53 | */ 54 | public static String sign(String username, String secret) { 55 | try { 56 | Date date = new Date(System.currentTimeMillis()+EXPIRE_TIME); 57 | Algorithm algorithm = Algorithm.HMAC256(secret); 58 | // 附带username信息 59 | return JWT.create() 60 | .withClaim("username", username) 61 | .withExpiresAt(date) 62 | .sign(algorithm); 63 | } catch (UnsupportedEncodingException e) { 64 | return null; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/ReaderDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.ReaderEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public class ReaderDao { 9 | public Boolean addReader(SqlSession sqlSession, ReaderEntity readerEntity) { 10 | int insertNum = sqlSession.insert("reader.insertReader", readerEntity); 11 | return insertNum == 1; 12 | } 13 | 14 | public Boolean changePassword(SqlSession sqlSession, ReaderEntity readerEntity) { 15 | int updateNum = sqlSession.update("reader.updatePassword", readerEntity); 16 | return updateNum == 1; 17 | } 18 | 19 | public String getPortraitByRid(SqlSession sqlSession, int rid) { 20 | return sqlSession.selectOne("reader.getPortraitByRid", rid); 21 | } 22 | 23 | public ReaderEntity getInfoByRid(SqlSession sqlSession, int rid) { 24 | return sqlSession.selectOne("reader.getInfoByRid", rid); 25 | } 26 | 27 | public ReaderEntity getReader(SqlSession sqlSession, ReaderEntity reader) { 28 | return sqlSession.selectOne("reader.getReader", reader); 29 | } 30 | 31 | public ReaderEntity getReaderByPhone(SqlSession sqlSession, String phone) { 32 | return sqlSession.selectOne("reader.getReaderByPhone", phone); 33 | } 34 | 35 | public ReaderEntity getReaderByUsername(SqlSession sqlSession, String username) { 36 | return sqlSession.selectOne("reader.getReaderByUsername", username); 37 | } 38 | 39 | public ReaderEntity getReaderByReaderName(SqlSession sqlSession, String readerName) { 40 | return sqlSession.selectOne("reader.getReaderByName", readerName); 41 | } 42 | 43 | public String getReaderRoleByRid(SqlSession sqlSession, int rid) { 44 | return sqlSession.selectOne("reader.getReaderRoleByRid", rid); 45 | } 46 | 47 | public Boolean updateAvatar(SqlSession sqlSession, ReaderEntity reader) { 48 | int updateNum = sqlSession.update("reader.updateAvatar", reader); 49 | return updateNum == 1; 50 | } 51 | 52 | public Boolean updateInfo(SqlSession sqlSession, ReaderEntity readerEntity) { 53 | int updateNum = sqlSession.update("reader.updateInfo", readerEntity); 54 | return updateNum == 1; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/PostDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.AttitudeEntity; 4 | import com.riyeyuedu.entity.PostEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | @Repository 12 | public class PostDao { 13 | public Boolean addPost(SqlSession sqlSession, PostEntity post) { 14 | int addNum = sqlSession.insert("post.insertPost", post); 15 | return addNum == 1; 16 | } 17 | 18 | public List> getPostByNid(SqlSession sqlSession, Long nid) { 19 | return sqlSession.selectList("post.selectPostByNid", nid); 20 | } 21 | 22 | public Map getPostByPid(SqlSession sqlSession, Long pid) { 23 | return sqlSession.selectOne("post.getPostByPid", pid); 24 | } 25 | 26 | public Integer getPostNumByNid(SqlSession sqlSession, Long nid) { 27 | return sqlSession.selectOne("post.getPostNumByNid", nid); 28 | } 29 | 30 | public Boolean addCommentNum(SqlSession sqlSession, Long pid) { 31 | int updateNum = sqlSession.update("post.addCommentNum", pid); 32 | return updateNum == 1; 33 | } 34 | 35 | public Boolean reduceCommentNUm(SqlSession sqlSession, Long pid) { 36 | int updateNum = sqlSession.update("post.reduceCommentNum", pid); 37 | return updateNum == 1; 38 | } 39 | 40 | public Boolean addLikeNum(SqlSession sqlSession, Long pid) { 41 | int updateNum = sqlSession.update("post.addLikeNum", pid); 42 | return updateNum == 1; 43 | } 44 | 45 | public Boolean reduceLikeNum(SqlSession sqlSession, Long pid) { 46 | int updateNum = sqlSession.update("post.reduceLikeNum", pid); 47 | return updateNum == 1; 48 | } 49 | 50 | public Boolean addAttitude(SqlSession sqlSession, AttitudeEntity attitudeEntity) { 51 | int addNum = sqlSession.insert("post.insertAttitude", attitudeEntity); 52 | return addNum == 1; 53 | } 54 | 55 | public Integer isAttitude(SqlSession sqlSession, AttitudeEntity attitudeEntity) { 56 | return sqlSession.selectOne("post.isAttitude", attitudeEntity); 57 | } 58 | 59 | public Boolean updateAttitude(SqlSession sqlSession, AttitudeEntity attitudeEntity) { 60 | int updateNum = sqlSession.update("post.updateAttitude", attitudeEntity); 61 | return updateNum == 1; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/ChapterController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.*; 4 | import com.riyeyuedu.service.ChapterService; 5 | import com.riyeyuedu.service.RecordService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * Created by 阳溢 on 2018/1/5. 14 | */ 15 | @RestController 16 | public class ChapterController { 17 | private ChapterService chapterService; 18 | 19 | private RecordService recordService; 20 | 21 | @Autowired 22 | public void setChapterService(ChapterService chapterService) { 23 | this.chapterService = chapterService; 24 | } 25 | 26 | @Autowired 27 | public void setRecordService(RecordService recordService) { 28 | this.recordService = recordService; 29 | } 30 | 31 | @RequestMapping(value = "/chapter/{cid}", method = RequestMethod.GET) 32 | @CrossOrigin 33 | public ResponseEntity getChapter(@PathVariable("cid") Long cid) { 34 | System.out.println("in"); 35 | System.out.println(cid); 36 | Map map = chapterService.getChapterByCid(cid); 37 | System.out.println(map); 38 | Long nid = (Long) map.get("nid"); 39 | Long fcid = chapterService.getFirstChapter(nid).getCid(); 40 | Long lcid = chapterService.getLastChapter(nid).getCid(); 41 | map.put("fcid", fcid); 42 | map.put("lcid", lcid); 43 | 44 | System.out.println(map); 45 | 46 | return new ResponseEntity(map); 47 | } 48 | 49 | @RequestMapping(value = "/user/continue/{uid}/{nid}") 50 | @CrossOrigin 51 | public ResponseEntity continueRead(@PathVariable("uid") int uid, @PathVariable("nid") Long nid) { 52 | RecordEntity recordEntity = new RecordEntity(); 53 | recordEntity.setUid(uid); 54 | recordEntity.setNid(nid); 55 | if (recordService.getRecord(recordEntity) != null) { 56 | return new ResponseEntity(recordService.getRecord(recordEntity).getCid()); 57 | } else { 58 | return new ResponseEntity(null); 59 | } 60 | } 61 | 62 | @RequestMapping(value = "/directory/{nid}", method = RequestMethod.GET) 63 | @ResponseBody 64 | public List getDirectoryByNid(@PathVariable("nid") Long nid) { 65 | return chapterService.getDirectoryByNid(nid); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/resources/mapping/UsersMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO user (username, password, portrait, phone, permission) 7 | VALUES (#{username}, #{password}, #{portrait}, #{phone}, #{permission}) 8 | 9 | 10 | 13 | 14 | 17 | 18 | 21 | 22 | 25 | 26 | 29 | 30 | 33 | 34 | 35 | UPDATE user SET username = #{username}, sex = #{sex}, birthday = #{birthday}, info = #{info} WHERE uid = #{uid} 36 | 37 | 38 | 39 | UPDATE user SET password = #{password} WHERE phone = #{phone} 40 | 41 | 42 | 43 | UPDATE user SET portrait = #{portrait} WHERE uid = #{uid} 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/ChapterService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.ChapterDao; 4 | import com.riyeyuedu.entity.ChapterEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * Created by 阳溢 on 2018/1/5. 14 | */ 15 | @Service 16 | public class ChapterService { 17 | private SqlSession sqlSession; 18 | 19 | private ChapterDao chapterDao; 20 | 21 | public ChapterService(SqlSession sqlSession) { 22 | this.sqlSession = sqlSession; 23 | } 24 | 25 | @Autowired 26 | public void setChapterDao(ChapterDao chapterDao) { 27 | this.chapterDao = chapterDao; 28 | } 29 | 30 | public Boolean addChapter(ChapterEntity chapter) { 31 | return chapterDao.addChapter(sqlSession, chapter); 32 | } 33 | 34 | public Boolean addDraft(ChapterEntity chapter) { 35 | return chapterDao.addDraft(sqlSession, chapter); 36 | } 37 | 38 | public List getDirectoryByNid(Long nid) { 39 | return chapterDao.getDirectoryByNid(sqlSession, nid); 40 | } 41 | 42 | public Map getChapterByCid(Long cid) { 43 | return chapterDao.getChapterByCid(sqlSession, cid); 44 | } 45 | 46 | public ChapterEntity getDraftByCid(Long cid) { 47 | return chapterDao.getDraftByCid(sqlSession, cid); 48 | } 49 | 50 | public ChapterEntity getFirstChapter(Long nid) { 51 | return chapterDao.getFirstChapter(sqlSession, nid); 52 | } 53 | 54 | public ChapterEntity getLastChapter(Long nid) { 55 | return chapterDao.getLastChapter(sqlSession, nid); 56 | } 57 | 58 | public ChapterEntity getNewChapter(Long nid) { 59 | return chapterDao.getNewChapter(sqlSession, nid); 60 | } 61 | 62 | public Boolean chapterAllowed(ChapterEntity chapter) { 63 | return chapterDao.chapterAllowed(sqlSession, chapter); 64 | } 65 | 66 | public List getChapterInfo(Long nid) { return chapterDao.getChapterInfo(sqlSession, nid); } 67 | 68 | public boolean updateDraft(ChapterEntity chapterEntity) { 69 | return chapterDao.updateDraft(sqlSession, chapterEntity); 70 | } 71 | 72 | public boolean updateContent(ChapterEntity chapterEntity) { 73 | return chapterDao.updateContent(sqlSession, chapterEntity); 74 | } 75 | 76 | public boolean deleteDraft(Long cid) { 77 | return chapterDao.deleteDraft(sqlSession, cid); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/security/Realm.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.security; 2 | 3 | import com.riyeyuedu.entity.UserEntity; 4 | import com.riyeyuedu.service.UserService; 5 | import com.riyeyuedu.util.JWTUtil; 6 | import org.apache.shiro.authc.AuthenticationException; 7 | import org.apache.shiro.authc.AuthenticationInfo; 8 | import org.apache.shiro.authc.AuthenticationToken; 9 | import org.apache.shiro.authc.SimpleAuthenticationInfo; 10 | import org.apache.shiro.authz.AuthorizationInfo; 11 | import org.apache.shiro.authz.SimpleAuthorizationInfo; 12 | import org.apache.shiro.realm.AuthorizingRealm; 13 | import org.apache.shiro.subject.PrincipalCollection; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | 17 | @Service 18 | public class Realm extends AuthorizingRealm { 19 | private UserService userService; 20 | 21 | @Autowired 22 | public void setReaderService(UserService userService) { 23 | this.userService = userService; 24 | } 25 | 26 | /** 27 | * 大坑!,必须重写此方法,不然Shiro会报错 28 | */ 29 | @Override 30 | public boolean supports(AuthenticationToken token) { 31 | return token instanceof JWToken; 32 | } 33 | 34 | /** 35 | * 只有当需要检测用户权限的时候才会调用此方法,例如checkRole,checkPermission之类的 36 | */ 37 | @Override 38 | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { 39 | String username = JWTUtil.getUsername(principals.toString()); 40 | UserEntity userEntity = userService.getReaderByName(username); 41 | SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); 42 | simpleAuthorizationInfo.addRole("reader"); 43 | return simpleAuthorizationInfo; 44 | } 45 | 46 | /** 47 | * 默认使用此方法进行用户名正确与否验证,错误抛出异常即可。 48 | */ 49 | @Override 50 | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException { 51 | String token = (String) auth.getCredentials(); 52 | // 解密获得username,用于和数据库进行对比 53 | String username = JWTUtil.getUsername(token); 54 | if (username == null) { 55 | throw new AuthenticationException("token invalid"); 56 | } 57 | 58 | UserEntity userEntity = userService.getReaderByName(username); 59 | if (userEntity == null) { 60 | throw new AuthenticationException("reader didn't existed!"); 61 | } 62 | 63 | if (! JWTUtil.verify(token, username, userEntity.getPassword())) { 64 | throw new AuthenticationException("Username or password error"); 65 | } 66 | 67 | return new SimpleAuthenticationInfo(token, token, "realm"); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/resources/mapping/BookCaseMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO bookcase (uid, type) VALUES (#{uid}, #{type}) 7 | 8 | 9 | 10 | INSERT INTO bookcase_user (bid, nid, level) VALUES (#{bid}, #{nid}, 0) 11 | 12 | 13 | 16 | 17 | 20 | 21 | 24 | 25 | 28 | 29 | 32 | 33 | 36 | 37 | 40 | 41 | 42 | DELETE FROM bookcase_user WHERE nid = #{nid} AND bid = #{bid} 43 | 44 | 45 | 46 | DELETE FROM bookcase WHERE bid = #{bid} 47 | 48 | 49 | 50 | UPDATE bookcase_user SET bid = #{bid} WHERE nid = #{nid} 51 | 52 | 53 | 54 | UPDATE bookcase_user SET level = #{level} WHERE nid = #{nid} AND bid = #{bid} 55 | 56 | 57 | 58 | UPDATE bookcase_user SET level = 0 WHERE nid = #{nid} AND bid = #{bid} 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/main/resources/mapping/ScoreMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO score (uid, nid, score, content, time, like_num) VALUES (#{uid}, #{nid}, #{score}, #{content}, #{time}, 0) 7 | 8 | 9 | 12 | 13 | 16 | 17 | 28 | 29 | 36 | 37 | 40 | 41 | 44 | 45 | 46 | UPDATE score SET score = #{score}, content = #{content}, time = #{time} WHERE uid = #{uid} AND nid = #{nid} 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/ChapterDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.ChapterEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | 11 | /** 12 | * Created by 阳溢 on 2018/1/5. 13 | */ 14 | @Repository 15 | public class ChapterDao { 16 | 17 | public Boolean addChapter(SqlSession sqlSession, ChapterEntity chapter) { 18 | int addNum = sqlSession.insert("chapter.insertChapter", chapter); 19 | return addNum == 1; 20 | } 21 | 22 | public Boolean addDraft(SqlSession sqlSession, ChapterEntity chapter) { 23 | int addNum = sqlSession.insert("chapter.insertDraft", chapter); 24 | return addNum == 1; 25 | } 26 | 27 | public List getDirectoryByNid(SqlSession sqlSession, Long nid) { 28 | return sqlSession.selectList("chapter.getDirectoryByNid", nid); 29 | } 30 | 31 | public Map getChapterByCid(SqlSession sqlSession, Long cid) { 32 | return sqlSession.selectOne("chapter.getChapterByCid", cid); 33 | } 34 | 35 | public ChapterEntity getDraftByCid(SqlSession sqlSession, Long cid){ 36 | return sqlSession.selectOne("chapter.getDraftByCid", cid); 37 | } 38 | 39 | public ChapterEntity getFirstChapter(SqlSession sqlSession, Long nid) { 40 | return sqlSession.selectOne("chapter.getFirstChapter", nid); 41 | } 42 | 43 | public ChapterEntity getLastChapter(SqlSession sqlSession, Long nid) { 44 | return sqlSession.selectOne("chapter.getLastChapter", nid); 45 | } 46 | 47 | public ChapterEntity getNewChapter(SqlSession sqlSession, Long nid) { 48 | return sqlSession.selectOne("chapter.getNewChapter", nid); 49 | } 50 | 51 | public Boolean chapterAllowed(SqlSession sqlSession, ChapterEntity chapter) { 52 | int updateNum = sqlSession.update("chapter.chapterAllowed", chapter); 53 | return updateNum == 1; 54 | } 55 | 56 | public List getChapterInfo(SqlSession sqlSession, Long nid) { 57 | return sqlSession.selectList("chapter.getChapterInfo", nid); 58 | } 59 | 60 | public boolean updateDraft(SqlSession sqlSession, ChapterEntity chapterEntity) { 61 | int updateNum = sqlSession.update("chapter.updateDraft", chapterEntity); 62 | return updateNum == 1; 63 | } 64 | 65 | public boolean updateContent(SqlSession sqlSession, ChapterEntity chapterEntity) { 66 | int updateNum = sqlSession.update("chapter.updateContent", chapterEntity); 67 | return updateNum == 1; 68 | } 69 | 70 | public boolean deleteDraft(SqlSession sqlSession, Long cid) { 71 | int updateNum = sqlSession.update("chapter.deleteDraft", cid); 72 | return updateNum == 1; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/BookCaseDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.BookCaseEntity; 4 | import org.apache.ibatis.session.SqlSession; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | @Repository 11 | public class BookCaseDao { 12 | public Boolean addBookCase(SqlSession sqlSession, BookCaseEntity bookCase) { 13 | int addNum = sqlSession.insert("bookCase.insertBookCase", bookCase); 14 | return addNum == 1; 15 | } 16 | 17 | public Boolean addNovelToBookcase(SqlSession sqlSession, Map map) { 18 | int addNum = sqlSession.insert("bookCase.insertNovelToBookcase", map); 19 | return addNum == 1; 20 | } 21 | 22 | public BookCaseEntity getBookcase(SqlSession sqlSession, BookCaseEntity bookCaseEntity) { 23 | return sqlSession.selectOne("bookCase.getBookcase", bookCaseEntity); 24 | } 25 | 26 | public BookCaseEntity isNovelInBookcase(SqlSession sqlSession, Map map) { 27 | return sqlSession.selectOne("bookCase.isNovelInBookcase", map); 28 | } 29 | 30 | public Boolean deleteNovelInBookCase(SqlSession sqlSession, Map map) { 31 | int deleteNum = sqlSession.delete("bookCase.deleteNovelInBookCase", map); 32 | return deleteNum == 1; 33 | } 34 | 35 | public Boolean deleteBookcase(SqlSession sqlSession, Long bid) { 36 | int deleteNum = sqlSession.delete("bookCase.deleteBookcase", bid); 37 | return deleteNum == 1; 38 | } 39 | 40 | public List> getAllBookcase(SqlSession sqlSession, int uid) { 41 | return sqlSession.selectList("bookCase.getAllBookcase", uid); 42 | } 43 | 44 | public Integer getBookNumByUid(SqlSession sqlSession, int uid) { 45 | return sqlSession.selectOne("bookCase.getBookNumByUid", uid); 46 | } 47 | 48 | public BookCaseEntity getDefaultBookcase(SqlSession sqlSession, int uid) { 49 | return sqlSession.selectOne("bookCase.getDefaultBookcase", uid); 50 | } 51 | 52 | public Boolean updateType(SqlSession sqlSession, Map map) { 53 | int updateNum = sqlSession.update("bookCase.updateType", map); 54 | return updateNum == 1; 55 | } 56 | 57 | public Boolean updateLevel(SqlSession sqlSession, Map map) { 58 | int updateNum = sqlSession.update("bookCase.updateLevel", map); 59 | return updateNum == 1; 60 | } 61 | 62 | public Map getTopNum(SqlSession sqlSession, Long bid) { 63 | return sqlSession.selectOne("bookCase.getTopNum", bid); 64 | } 65 | 66 | public Map getNovelCount(SqlSession sqlSession, Long bid) { 67 | return sqlSession.selectOne("bookCase.getNovelCount", bid); 68 | } 69 | 70 | public Boolean updateLevelDown(SqlSession sqlSession, Map map) { 71 | int updateNum = sqlSession.update("bookCase.updateLevelDown", map); 72 | return updateNum == 1; 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/BookCaseService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.BookCaseDao; 4 | import com.riyeyuedu.entity.BookCaseEntity; 5 | import org.apache.ibatis.session.SqlSession; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.Collections; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | @Service 14 | public class BookCaseService { 15 | private SqlSession sqlSession; 16 | 17 | private BookCaseDao bookCaseDao; 18 | 19 | public BookCaseService(SqlSession sqlSession) { 20 | this.sqlSession = sqlSession; 21 | } 22 | 23 | @Autowired 24 | public void setBookCaseDao(BookCaseDao bookCaseDao) { 25 | this.bookCaseDao = bookCaseDao; 26 | } 27 | 28 | public Boolean addBookCase(BookCaseEntity bookCase) { 29 | return bookCaseDao.addBookCase(sqlSession, bookCase); 30 | } 31 | 32 | public Boolean addNovelToBookcase(Map map) { 33 | return bookCaseDao.addNovelToBookcase(sqlSession, map); 34 | } 35 | 36 | public BookCaseEntity getBookCase(BookCaseEntity bookCaseEntity) { 37 | return bookCaseDao.getBookcase(sqlSession, bookCaseEntity); 38 | } 39 | 40 | public BookCaseEntity isNovelInBookcase(Map map) { 41 | return bookCaseDao.isNovelInBookcase(sqlSession, map); 42 | } 43 | 44 | public Boolean deleteNovelInBookCase(Map map) { 45 | return bookCaseDao.deleteNovelInBookCase(sqlSession, map); 46 | } 47 | 48 | public Boolean deleteBookcase(Long bid) { 49 | return bookCaseDao.deleteBookcase(sqlSession, bid); 50 | } 51 | 52 | public List> getAllBookcase(int uid) { 53 | List> list = bookCaseDao.getAllBookcase(sqlSession, uid); 54 | for (Map map : list) { 55 | if (map.get("type").equals("默认分组")) { 56 | int index = list.indexOf(map); 57 | Collections.swap(list, 0, index); 58 | } 59 | } 60 | return list; 61 | } 62 | 63 | public Integer getBookNumByUid(int uid) { 64 | return bookCaseDao.getBookNumByUid(sqlSession, uid); 65 | } 66 | 67 | public BookCaseEntity getDefaultBookcase(int uid) { 68 | return bookCaseDao.getDefaultBookcase(sqlSession, uid); 69 | } 70 | 71 | public Boolean removeBookcase(Map map) { 72 | return bookCaseDao.updateType(sqlSession, map); 73 | } 74 | 75 | public Boolean toTop(Map map) { 76 | return bookCaseDao.updateLevel(sqlSession, map); 77 | } 78 | 79 | public Map getTopNum(Long bid) { 80 | return bookCaseDao.getTopNum(sqlSession, bid); 81 | } 82 | 83 | public Map getNovelCount(Long bid) { 84 | return bookCaseDao.getNovelCount(sqlSession, bid); 85 | } 86 | 87 | public Boolean updateLevelDown(Map map) { 88 | return bookCaseDao.updateLevelDown(sqlSession, map); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/util/SmsUtil.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.util; 2 | 3 | import com.aliyuncs.DefaultAcsClient; 4 | import com.aliyuncs.IAcsClient; 5 | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; 6 | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; 7 | import com.aliyuncs.exceptions.ClientException; 8 | import com.aliyuncs.http.MethodType; 9 | import com.aliyuncs.profile.DefaultProfile; 10 | import com.aliyuncs.profile.IClientProfile; 11 | import com.riyeyuedu.entity.ResponseEntity; 12 | 13 | public class SmsUtil { 14 | 15 | public static ResponseEntity sendSms(String random, String phone) { 16 | //设置超时时间-可自行调整 17 | System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); 18 | System.setProperty("sun.net.client.defaultReadTimeout", "10000"); 19 | //初始化ascClient需要的几个参数 20 | final String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改) 21 | final String domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改) 22 | //替换成你的AK 23 | final String accessKeyId = "LTAICBaKv7FrgzZf";//你的accessKeyId,参考本文档步骤2 24 | final String accessKeySecret = "0CWhs6GjKdOqhGWNxZod3jM1npFdE7";//你的accessKeySecret,参考本文档步骤2 25 | //初始化ascClient,暂时不支持多region(请勿修改) 26 | IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, 27 | accessKeySecret); 28 | try { 29 | DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); 30 | } catch (ClientException e) { 31 | e.printStackTrace(); 32 | return new ResponseEntity(400, "内部错误,请稍后再试", null); 33 | } 34 | IAcsClient acsClient = new DefaultAcsClient(profile); 35 | //组装请求对象 36 | SendSmsRequest request = new SendSmsRequest(); 37 | //使用post提交 38 | request.setMethod(MethodType.POST); 39 | //必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式;发送国际/港澳台消息时,接收号码格式为00+国际区号+号码,如“0085200000000” 40 | request.setPhoneNumbers(phone); 41 | //必填:短信签名-可在短信控制台中找到 42 | request.setSignName("riyeyuedu"); 43 | //必填:短信模板-可在短信控制台中找到 44 | request.setTemplateCode("SMS_136465125"); 45 | 46 | //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为 47 | //友情提示:如果JSON中需要带换行符,请参照标准的JSON协议对换行符的要求,比如短信内容中包含\r\n的情况在JSON中需要表示成\\r\\n,否则会导致JSON在服务端解析失败 48 | request.setTemplateParam("{\"code\":\"" + random + "\"}"); 49 | 50 | //请求失败这里会抛ClientException异常 51 | SendSmsResponse sendSmsResponse = null; 52 | try { 53 | sendSmsResponse = acsClient.getAcsResponse(request); 54 | } catch (ClientException e) { 55 | e.printStackTrace(); 56 | return new ResponseEntity(400, sendSmsResponse.getCode(), null); 57 | } 58 | if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) { 59 | return new ResponseEntity("验证码已发送"); 60 | } else { 61 | return new ResponseEntity(400, "内部错误,请稍后再试", sendSmsResponse.getCode()); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/resources/mapping/PostMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO post (nid, uid, like_num, theme, content, update_time, level, reply_num) 7 | VALUES (#{nid}, #{uid}, 0, #{theme}, #{content}, #{updateTime}, 0, 0) 8 | 9 | 10 | 11 | INSERT INTO attitude (uid, pid, state) VALUES (#{uid}, #{pid}, #{state}) 12 | 13 | 14 | 17 | 18 | 25 | 26 | 31 | 32 | 35 | 36 | 37 | UPDATE post SET reply_num = post.reply_num + 1 WHERE pid = #{pid} 38 | 39 | 40 | 41 | UPDATE post SET reply_num = post.reply_num - 1 WHERE pid = #{pid} 42 | 43 | 44 | 45 | UPDATE post SET like_num = like_num + 1 WHERE pid = #{pid} 46 | 47 | 48 | 49 | UPDATE post SET like_num = like_num - 1 WHERE pid = #{pid} 50 | 51 | 52 | 53 | UPDATE attitude SET state = #{state} WHERE uid = #{uid} AND pid = #{pid} 54 | 55 | 56 | 57 | DELETE FROM post WHERE pid = #{pid} 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/PostController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.AttitudeEntity; 4 | import com.riyeyuedu.entity.PostEntity; 5 | import com.riyeyuedu.entity.ReplyEntity; 6 | import com.riyeyuedu.entity.ResponseEntity; 7 | import com.riyeyuedu.service.NovelService; 8 | import com.riyeyuedu.service.PostService; 9 | import com.riyeyuedu.service.ReplyService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.Date; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @RestController 18 | public class PostController { 19 | private PostService postService; 20 | 21 | private NovelService novelService; 22 | 23 | private ReplyService replyService; 24 | 25 | @Autowired 26 | public void setPostService(PostService postService) { 27 | this.postService = postService; 28 | } 29 | 30 | @Autowired 31 | public void setNovelService(NovelService novelService) { 32 | this.novelService = novelService; 33 | } 34 | 35 | @Autowired 36 | public void setReplyService(ReplyService replyService) { 37 | this.replyService = replyService; 38 | } 39 | 40 | @RequestMapping(value = "/post/{nid}") 41 | @CrossOrigin 42 | public ResponseEntity getPost(@PathVariable Long nid) { 43 | Map map = new HashMap<>(); 44 | map.put("novel", novelService.getTitleByNid(nid)); 45 | map.put("post", postService.getPostByNid(nid)); 46 | map.put("num", postService.getPostNumByNid(nid)); 47 | return new ResponseEntity(map); 48 | } 49 | 50 | @RequestMapping(value = "/reply/{nid}/{pid}") 51 | @CrossOrigin 52 | public ResponseEntity getReply( @PathVariable Long nid,@PathVariable Long pid) { 53 | Map map = new HashMap<>(); 54 | map.put("post", postService.getPostByPid(pid)); 55 | map.put("reply", replyService.getReplyByPid(pid)); 56 | map.put("novel", novelService.getTitleByNid(nid)); 57 | return new ResponseEntity(map); 58 | } 59 | 60 | @RequestMapping(value = "/sendReply", method = RequestMethod.POST) 61 | @CrossOrigin 62 | public ResponseEntity sendReply(@RequestBody ReplyEntity replyEntity) { 63 | replyEntity.setTime(new Date().getTime()); 64 | replyService.addReply(replyEntity); 65 | postService.addCommentNum(replyEntity.getPid()); 66 | return new ResponseEntity(replyEntity); 67 | } 68 | 69 | @RequestMapping(value = "/putPost", method = RequestMethod.POST) 70 | @CrossOrigin 71 | public ResponseEntity putPost(@RequestBody PostEntity postEntity) { 72 | postEntity.setUpdateTime(new Date().getTime()); 73 | return new ResponseEntity(postService.addPost(postEntity)); 74 | } 75 | 76 | @RequestMapping(value = "/toAttitude/{uid}/{pid}/{state}") 77 | @CrossOrigin 78 | public ResponseEntity toAttitude(@PathVariable int uid, @PathVariable Long pid, @PathVariable int state) { 79 | AttitudeEntity attitudeEntity = new AttitudeEntity(); 80 | attitudeEntity.setPid(pid); 81 | attitudeEntity.setUid(uid); 82 | attitudeEntity.setState(state); 83 | 84 | return new ResponseEntity(postService.toAttitude(attitudeEntity)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/config/ShiroConfig.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.config; 2 | 3 | import com.riyeyuedu.security.JWTFilter; 4 | import com.riyeyuedu.security.Realm; 5 | import org.apache.shiro.mgt.DefaultSessionStorageEvaluator; 6 | import org.apache.shiro.mgt.DefaultSubjectDAO; 7 | import org.apache.shiro.spring.LifecycleBeanPostProcessor; 8 | import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; 9 | import org.apache.shiro.spring.web.ShiroFilterFactoryBean; 10 | import org.apache.shiro.web.mgt.DefaultWebSecurityManager; 11 | import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.context.annotation.DependsOn; 15 | 16 | import javax.servlet.Filter; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | @Configuration 21 | public class ShiroConfig { 22 | 23 | @Bean("securityManager") 24 | public DefaultWebSecurityManager getManager(Realm realm) { 25 | DefaultWebSecurityManager manager = new DefaultWebSecurityManager(); 26 | // 使用自己的realm 27 | manager.setRealm(realm); 28 | 29 | /* 30 | * 关闭shiro自带的session,详情见文档 31 | * http://shiro.apache.org/session-management.html#SessionManagement-StatelessApplications%28Sessionless%29 32 | */ 33 | DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO(); 34 | DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator(); 35 | defaultSessionStorageEvaluator.setSessionStorageEnabled(false); 36 | subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator); 37 | manager.setSubjectDAO(subjectDAO); 38 | 39 | return manager; 40 | } 41 | 42 | @Bean("shiroFilter") 43 | public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) { 44 | ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean(); 45 | 46 | // 添加自己的过滤器并且取名为jwt 47 | Map filterMap = new HashMap<>(); 48 | filterMap.put("jwt", new JWTFilter()); 49 | factoryBean.setFilters(filterMap); 50 | 51 | factoryBean.setSecurityManager(securityManager); 52 | factoryBean.setUnauthorizedUrl("/401"); 53 | 54 | /* 55 | * 自定义url规则 56 | * http://shiro.apache.org/web.html#urls- 57 | */ 58 | Map filterRuleMap = new HashMap<>(); 59 | // 所有请求通过我们自己的JWT Filter 60 | filterRuleMap.put("/**", "jwt"); 61 | // 访问401和404页面不通过我们的Filter 62 | filterRuleMap.put("/401", "anon"); 63 | factoryBean.setFilterChainDefinitionMap(filterRuleMap); 64 | return factoryBean; 65 | } 66 | 67 | /** 68 | * 下面的代码是添加注解支持 69 | */ 70 | @Bean 71 | @DependsOn("lifecycleBeanPostProcessor") 72 | public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { 73 | DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); 74 | // 强制使用cglib,防止重复代理和可能引起代理出错的问题 75 | // https://zhuanlan.zhihu.com/p/29161098 76 | defaultAdvisorAutoProxyCreator.setProxyTargetClass(true); 77 | return defaultAdvisorAutoProxyCreator; 78 | } 79 | 80 | @Bean 81 | public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() { 82 | return new LifecycleBeanPostProcessor(); 83 | } 84 | 85 | @Bean 86 | public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) { 87 | AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor(); 88 | advisor.setSecurityManager(securityManager); 89 | return advisor; 90 | } 91 | } -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/security/JWTFilter.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.security; 2 | 3 | import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | 9 | import javax.servlet.ServletRequest; 10 | import javax.servlet.ServletResponse; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | public class JWTFilter extends BasicHttpAuthenticationFilter { 16 | 17 | private Logger LOGGER = LoggerFactory.getLogger(this.getClass()); 18 | 19 | /** 20 | * 判断用户是否想要登入。 21 | * 检测header里面是否包含Authorization字段即可 22 | */ 23 | @Override 24 | protected boolean isLoginAttempt(ServletRequest request, ServletResponse response) { 25 | HttpServletRequest req = (HttpServletRequest) request; 26 | String authorization = req.getHeader("Authorization"); 27 | return authorization != null; 28 | } 29 | 30 | /** 31 | * 32 | */ 33 | @Override 34 | protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception { 35 | HttpServletRequest httpServletRequest = (HttpServletRequest) request; 36 | String authorization = httpServletRequest.getHeader("Authorization"); 37 | 38 | JWToken token = new JWToken(authorization); 39 | // 提交给realm进行登入,如果错误他会抛出异常并被捕获 40 | getSubject(request, response).login(token); 41 | // 如果没有抛出异常则代表登入成功,返回true 42 | return true; 43 | } 44 | 45 | /** 46 | * 这里我们详细说明下为什么最终返回的都是true,即允许访问 47 | * 例如我们提供一个地址 GET /article 48 | * 登入用户和游客看到的内容是不同的 49 | * 如果在这里返回了false,请求会被直接拦截,用户看不到任何东西 50 | * 所以我们在这里返回true,Controller中可以通过 subject.isAuthenticated() 来判断用户是否登入 51 | * 如果有些资源只有登入用户才能访问,我们只需要在方法上面加上 @RequiresAuthentication 注解即可 52 | * 但是这样做有一个缺点,就是不能够对GET,POST等请求进行分别过滤鉴权(因为我们重写了官方的方法),但实际上对应用影响不大 53 | */ 54 | @Override 55 | protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) { 56 | if (isLoginAttempt(request, response)) { 57 | try { 58 | executeLogin(request, response); 59 | } catch (Exception e) { 60 | response401(request, response); 61 | } 62 | } 63 | return true; 64 | } 65 | 66 | /** 67 | * 对跨域提供支持 68 | */ 69 | @Override 70 | protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception { 71 | HttpServletRequest httpServletRequest = (HttpServletRequest) request; 72 | HttpServletResponse httpServletResponse = (HttpServletResponse) response; 73 | httpServletResponse.setHeader("Access-control-Allow-Origin", httpServletRequest.getHeader("Origin")); 74 | httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE"); 75 | httpServletResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers")); 76 | // 跨域时会首先发送一个option请求,这里我们给option请求直接返回正常状态 77 | if (httpServletRequest.getMethod().equals(RequestMethod.OPTIONS.name())) { 78 | httpServletResponse.setStatus(HttpStatus.OK.value()); 79 | return false; 80 | } 81 | return super.preHandle(request, response); 82 | } 83 | 84 | /** 85 | * 将非法请求跳转到 /401 86 | */ 87 | private void response401(ServletRequest req, ServletResponse resp) { 88 | try { 89 | HttpServletResponse httpServletResponse = (HttpServletResponse) resp; 90 | httpServletResponse.sendRedirect("/401"); 91 | } catch (IOException e) { 92 | LOGGER.error(e.getMessage()); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /src/main/resources/mapping/ChapterMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | INSERT INTO chapter (nid, chapter_name, content, create_time, word_num, allow) 7 | VALUES (#{nid}, #{chapterName}, #{content}, #{createTime}, #{wordNum}, #{allow}) 8 | 9 | 10 | 11 | INSERT INTO chapter (nid, chapter_name, draft, create_time, word_num, allow, is_draft) 12 | VALUES (#{nid}, #{chapterName}, #{draft}, #{createTime}, #{wordNum}, #{allow}, #{isDraft}) 13 | 14 | 15 | 18 | 19 | 29 | 30 | 33 | 34 | 37 | 38 | 41 | 42 | 47 | 48 | 51 | 52 | 55 | 56 | 57 | UPDATE chapter SET allow = 1 WHERE nid = #{nid} AND cid = #{cid} 58 | 59 | 60 | 61 | update chapter set draft = #{draft} where cid = #{cid} 62 | 63 | 64 | 65 | update chapter set content = #{content}, allow = 1 where cid = #{cid} 66 | 67 | 68 | 69 | update chapter set is_draft = 0 where cid = #{cid} 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/AuthorController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.ChapterEntity; 4 | import com.riyeyuedu.entity.NovelEntity; 5 | import com.riyeyuedu.entity.ResponseEntity; 6 | import com.riyeyuedu.service.ChapterService; 7 | import com.riyeyuedu.service.NovelService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.Date; 12 | 13 | @RestController 14 | public class AuthorController { 15 | private NovelService novelService; 16 | 17 | private ChapterService chapterService; 18 | 19 | @Autowired 20 | public void setNovelService(NovelService novelService) { 21 | this.novelService = novelService; 22 | } 23 | 24 | @Autowired 25 | public void setChapterService(ChapterService chapterService) { 26 | this.chapterService = chapterService; 27 | } 28 | 29 | @RequestMapping(value = "/author/createNovel", method = RequestMethod.POST) 30 | @CrossOrigin 31 | public ResponseEntity createNovel(@RequestBody NovelEntity novelEntity) { 32 | novelEntity.setAllow(0); 33 | novelEntity.setChapterNum(0); 34 | novelEntity.setClickNum(0); 35 | novelEntity.setClickNum(0); 36 | novelEntity.setCollectNum(0); 37 | novelEntity.setCreateTime(new Date().getTime()); 38 | novelEntity.setRecommendNum(0); 39 | novelEntity.setWordNum(0); 40 | novelEntity.setScore(1.0); 41 | novelEntity.setState(-1); 42 | novelEntity.setCover("https://nealcaffrey.oss-cn-beijing.aliyuncs.com/default/default.png"); 43 | 44 | novelService.addNovel(novelEntity); 45 | 46 | return new ResponseEntity(200, "success", novelEntity.getNid()); 47 | } 48 | 49 | @RequestMapping(value = "/author/novel/{uid}") 50 | @CrossOrigin 51 | public ResponseEntity getNovel(@PathVariable("uid") int uid) { 52 | return new ResponseEntity(200, "success", novelService.getNovelByUid(uid)); 53 | } 54 | 55 | @RequestMapping(value = "/author/chapter/{nid}") 56 | @CrossOrigin 57 | public ResponseEntity getChapters(@PathVariable("nid") Long nid) { 58 | return new ResponseEntity(200, "success", chapterService.getChapterInfo(nid)); 59 | } 60 | 61 | @RequestMapping(value = "/author/createChapter", method = RequestMethod.POST) 62 | @CrossOrigin 63 | public ResponseEntity createChapter(@RequestBody ChapterEntity chapterEntity) { 64 | chapterEntity.setCreateTime(new Date().getTime()); 65 | chapterEntity.setWordNum(chapterEntity.getContent().length()); 66 | 67 | //未写后台,上传的章节暂时默认为通过审核 68 | chapterEntity.setAllow(1); 69 | if (chapterEntity.getCid() != null) { 70 | chapterService.updateContent(chapterEntity); 71 | return new ResponseEntity(200, "success", true); 72 | } else { 73 | chapterService.addChapter(chapterEntity); 74 | novelService.addChapterNum(chapterEntity.getNid()); 75 | return new ResponseEntity(200, "success", chapterEntity.getCid()); 76 | } 77 | } 78 | 79 | @RequestMapping(value = "/author/createDraft", method = RequestMethod.POST) 80 | @CrossOrigin 81 | public ResponseEntity createDraft(@RequestBody ChapterEntity chapterEntity) { 82 | 83 | chapterEntity.setCreateTime(new Date().getTime()); 84 | chapterEntity.setWordNum(chapterEntity.getDraft().length()); 85 | chapterEntity.setAllow(0); 86 | chapterEntity.setIsDraft(1); 87 | 88 | if (chapterEntity.getCid() != null) { 89 | chapterService.updateDraft(chapterEntity); 90 | return new ResponseEntity(200, "success", true); 91 | } else { 92 | chapterService.addDraft(chapterEntity); 93 | return new ResponseEntity(200, "success", chapterEntity.getCid()); 94 | } 95 | } 96 | 97 | @RequestMapping(value = "/author/getDraft/{cid}") 98 | @CrossOrigin 99 | public ResponseEntity getDraft(@PathVariable("cid") Long cid) { 100 | return new ResponseEntity(200, "success", chapterService.getDraftByCid(cid)); 101 | } 102 | 103 | @RequestMapping(value = "/author/deleteDraft/{cid}") 104 | @CrossOrigin 105 | public ResponseEntity deleteDraft(@PathVariable("cid") Long cid) { 106 | chapterService.deleteDraft(cid); 107 | 108 | return new ResponseEntity(200, "success", true); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/entity/NovelEntity.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.entity; 2 | 3 | public class NovelEntity { 4 | private Long nid; 5 | 6 | private String title; 7 | 8 | private Integer uid; 9 | 10 | private Integer lid; 11 | 12 | private Integer did; 13 | 14 | private String introduction; 15 | 16 | private String info; 17 | 18 | private Double score; 19 | 20 | private Integer state; 21 | 22 | private String cover; 23 | 24 | private Long createTime; 25 | 26 | private Long updateTime; 27 | 28 | private Integer wordNum; 29 | 30 | private Integer clickNum; 31 | 32 | private Integer collectNum; 33 | 34 | private Integer recommendNum; 35 | 36 | private Integer chapterNum; 37 | 38 | private Long recentChapterId; 39 | 40 | private int allow; 41 | 42 | private int level; 43 | 44 | public Long getNid() { 45 | return nid; 46 | } 47 | 48 | public void setNid(Long nid) { 49 | this.nid = nid; 50 | } 51 | 52 | public String getTitle() { 53 | return title; 54 | } 55 | 56 | public void setTitle(String title) { 57 | this.title = title; 58 | } 59 | 60 | public Integer getUid() { 61 | return uid; 62 | } 63 | 64 | public void setUid(Integer uid) { 65 | this.uid = uid; 66 | } 67 | 68 | public Integer getLid() { 69 | return lid; 70 | } 71 | 72 | public void setLid(Integer lid) { 73 | this.lid = lid; 74 | } 75 | 76 | public Integer getDid() { 77 | return did; 78 | } 79 | 80 | public Integer getCollectNum() { 81 | return collectNum; 82 | } 83 | 84 | public void setCollectNum(Integer collectNum) { 85 | this.collectNum = collectNum; 86 | } 87 | 88 | public void setDid(Integer did) { 89 | this.did = did; 90 | } 91 | 92 | public String getIntroduction() { 93 | return introduction; 94 | } 95 | 96 | public void setIntroduction(String introduction) { 97 | this.introduction = introduction; 98 | } 99 | 100 | public String getInfo() { 101 | return info; 102 | } 103 | 104 | public void setInfo(String info) { 105 | this.info = info; 106 | } 107 | 108 | public Double getScore() { 109 | return score; 110 | } 111 | 112 | public void setScore(Double score) { 113 | this.score = score; 114 | } 115 | 116 | public Integer getState() { 117 | return state; 118 | } 119 | 120 | public void setState(Integer state) { 121 | this.state = state; 122 | } 123 | 124 | public String getCover() { 125 | return cover; 126 | } 127 | 128 | public void setCover(String cover) { 129 | this.cover = cover; 130 | } 131 | 132 | public Long getCreateTime() { 133 | return createTime; 134 | } 135 | 136 | public void setCreateTime(Long createTime) { 137 | this.createTime = createTime; 138 | } 139 | 140 | public Long getUpdateTime() { 141 | return updateTime; 142 | } 143 | 144 | public void setUpdateTime(Long updateTime) { 145 | this.updateTime = updateTime; 146 | } 147 | 148 | public Integer getWordNum() { 149 | return wordNum; 150 | } 151 | 152 | public void setWordNum(Integer wordNum) { 153 | this.wordNum = wordNum; 154 | } 155 | 156 | public Integer getClickNum() { 157 | return clickNum; 158 | } 159 | 160 | public void setClickNum(Integer clickNum) { 161 | this.clickNum = clickNum; 162 | } 163 | 164 | public Integer getRecommendNum() { 165 | return recommendNum; 166 | } 167 | 168 | public void setRecommendNum(Integer recommendNum) { 169 | this.recommendNum = recommendNum; 170 | } 171 | 172 | public Integer getChapterNum() { 173 | return chapterNum; 174 | } 175 | 176 | public void setChapterNum(Integer chapterNum) { 177 | this.chapterNum = chapterNum; 178 | } 179 | 180 | public Long getRecentChapterId() { 181 | return recentChapterId; 182 | } 183 | 184 | public void setRecentChapterId(Long recentChapterId) { 185 | this.recentChapterId = recentChapterId; 186 | } 187 | 188 | public int getAllow() { 189 | return allow; 190 | } 191 | 192 | public void setAllow(int allow) { 193 | this.allow = allow; 194 | } 195 | 196 | public int getLevel() { 197 | return level; 198 | } 199 | 200 | public void setLevel(int level) { 201 | this.level = level; 202 | } 203 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.riyeyuedu 7 | reader 8 | 0.0.1-SNAPSHOT 9 | 10 | reader 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 1.5.9.RELEASE 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | 1.3.1 40 | 41 | 42 | 43 | mysql 44 | mysql-connector-java 45 | runtime 46 | 47 | 48 | 49 | net.sourceforge.nekohtml 50 | nekohtml 51 | 1.9.22 52 | 53 | 54 | 55 | 56 | org.json 57 | json 58 | 20160810 59 | 60 | 61 | 62 | 63 | com.aliyun.oss 64 | aliyun-sdk-oss 65 | 2.8.2 66 | 67 | 68 | 69 | 70 | com.aliyun 71 | aliyun-java-sdk-core 72 | 2.1.4 73 | 74 | 75 | 76 | 77 | 78 | com.aliyun.mns 79 | aliyun-sdk-mns 80 | 1.1.8.4 81 | 82 | 83 | 84 | com.aliyun 85 | aliyun-java-sdk-dysmsapi 86 | 1.1.0 87 | 88 | 89 | 90 | com.github.pagehelper 91 | pagehelper 92 | 5.0.4 93 | 94 | 95 | 96 | org.apache.shiro 97 | shiro-spring 98 | 1.3.2 99 | 100 | 101 | 102 | com.auth0 103 | java-jwt 104 | 3.2.0 105 | 106 | 107 | 108 | 109 | org.springframework.boot 110 | spring-boot-starter-data-redis 111 | 1.5.2.RELEASE 112 | 113 | 114 | 115 | 116 | org.springframework.boot 117 | spring-boot-starter-cache 118 | 1.3.0.RELEASE 119 | 120 | 121 | 122 | 123 | 124 | 125 | org.springframework.boot 126 | spring-boot-maven-plugin 127 | 128 | 129 | 130 | org.apache.maven.plugins 131 | maven-compiler-plugin 132 | 3.7.0 133 | 134 | 1.8 135 | 1.8 136 | UTF-8 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/RedisService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.*; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | import java.util.Set; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | @Service 13 | public class RedisService { 14 | @Autowired 15 | private RedisTemplate redisTemplate; 16 | /** 17 | * 写入缓存 18 | * @param key 19 | * @param value 20 | * @return 21 | */ 22 | public boolean set(final String key, Object value) { 23 | boolean result = false; 24 | try { 25 | ValueOperations operations = redisTemplate.opsForValue(); 26 | operations.set(key, value); 27 | result = true; 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | return result; 32 | } 33 | /** 34 | * 写入缓存设置时效时间 35 | * @param key 36 | * @param value 37 | * @return 38 | */ 39 | public boolean set(final String key, Object value, Long expireTime) { 40 | boolean result = false; 41 | try { 42 | ValueOperations operations = redisTemplate.opsForValue(); 43 | operations.set(key, value); 44 | redisTemplate.expire(key, expireTime, TimeUnit.SECONDS); 45 | result = true; 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | return result; 50 | } 51 | /** 52 | * 批量删除对应的value 53 | * @param keys 54 | */ 55 | public void remove(final String... keys) { 56 | for (String key : keys) { 57 | remove(key); 58 | } 59 | } 60 | 61 | /** 62 | * 批量删除key 63 | * @param pattern 64 | */ 65 | public void removePattern(final String pattern) { 66 | Set keys = redisTemplate.keys(pattern); 67 | if (keys.size() > 0) 68 | redisTemplate.delete(keys); 69 | } 70 | /** 71 | * 删除对应的value 72 | * @param key 73 | */ 74 | public void remove(final String key) { 75 | if (exists(key)) { 76 | redisTemplate.delete(key); 77 | } 78 | } 79 | /** 80 | * 判断缓存中是否有对应的value 81 | * @param key 82 | * @return 83 | */ 84 | public boolean exists(final String key) { 85 | return redisTemplate.hasKey(key); 86 | } 87 | /** 88 | * 读取缓存 89 | * @param key 90 | * @return 91 | */ 92 | public Object get(final String key) { 93 | Object result = null; 94 | ValueOperations operations = redisTemplate.opsForValue(); 95 | result = operations.get(key); 96 | return result; 97 | } 98 | /** 99 | * 哈希 添加 100 | * @param key 101 | * @param hashKey 102 | * @param value 103 | */ 104 | public void hmSet(String key, Object hashKey, Object value){ 105 | HashOperations hash = redisTemplate.opsForHash(); 106 | hash.put(key,hashKey,value); 107 | } 108 | 109 | /** 110 | * 哈希获取数据 111 | * @param key 112 | * @param hashKey 113 | * @return 114 | */ 115 | public Object hmGet(String key, Object hashKey){ 116 | HashOperations hash = redisTemplate.opsForHash(); 117 | return hash.get(key,hashKey); 118 | } 119 | 120 | /** 121 | * 列表添加 122 | * @param k 123 | * @param v 124 | */ 125 | public void lPush(String k,Object v){ 126 | ListOperations list = redisTemplate.opsForList(); 127 | list.rightPush(k,v); 128 | } 129 | 130 | /** 131 | * 列表获取 132 | * @param k 133 | * @param l 134 | * @param l1 135 | * @return 136 | */ 137 | public List lRange(String k, long l, long l1){ 138 | ListOperations list = redisTemplate.opsForList(); 139 | return list.range(k,l,l1); 140 | } 141 | 142 | /** 143 | * 集合添加 144 | * @param key 145 | * @param value 146 | */ 147 | public void add(String key,Object value){ 148 | SetOperations set = redisTemplate.opsForSet(); 149 | set.add(key,value); 150 | } 151 | 152 | /** 153 | * 集合获取 154 | * @param key 155 | * @return 156 | */ 157 | public Set setMembers(String key){ 158 | SetOperations set = redisTemplate.opsForSet(); 159 | return set.members(key); 160 | } 161 | 162 | /** 163 | * 有序集合添加 164 | * @param key 165 | * @param value 166 | * @param scoure 167 | */ 168 | public void zAdd(String key,Object value,double scoure){ 169 | ZSetOperations zset = redisTemplate.opsForZSet(); 170 | zset.add(key,value,scoure); 171 | } 172 | 173 | /** 174 | * 有序集合获取 175 | * @param key 176 | * @param scoure 177 | * @param scoure1 178 | * @return 179 | */ 180 | public Set rangeByScore(String key, double scoure, double scoure1){ 181 | ZSetOperations zset = redisTemplate.opsForZSet(); 182 | return zset.rangeByScore(key, scoure, scoure1); 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/service/NovelService.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.service; 2 | 3 | import com.riyeyuedu.dao.NovelDao; 4 | import com.riyeyuedu.entity.BookCaseEntity; 5 | import com.riyeyuedu.entity.NovelEntity; 6 | import com.riyeyuedu.entity.RecordEntity; 7 | import org.apache.ibatis.session.SqlSession; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * Created by 阳溢 on 2018/1/5. 17 | */ 18 | @Service 19 | public class NovelService { 20 | private SqlSession sqlSession; 21 | 22 | private NovelDao novelDao; 23 | 24 | public NovelService(SqlSession sqlSession) { 25 | this.sqlSession = sqlSession; 26 | } 27 | 28 | @Autowired 29 | public void setNovelDao(NovelDao novelDao) { 30 | this.novelDao = novelDao; 31 | } 32 | 33 | public boolean addNovel(NovelEntity novel) { 34 | return novelDao.addNovel(sqlSession, novel); 35 | } 36 | 37 | public List> getAllNovel(Map map) { 38 | return novelDao.getAllNovel(sqlSession, map); 39 | } 40 | 41 | public Map getNovelByNid(Long nid) { 42 | return novelDao.getNovelByNid(sqlSession, nid); 43 | } 44 | 45 | public Map getTitleByNid(Long nid) { 46 | return novelDao.getTitleByNid(sqlSession, nid); 47 | } 48 | 49 | public void addClickNum(Long nid) { 50 | novelDao.addClickNum(sqlSession, nid); 51 | } 52 | 53 | public List> getNovelByLidL5(int lid) { 54 | return novelDao.getNovelByLidL5(sqlSession, lid); 55 | } 56 | 57 | public List> getNovelByRecentL23() { 58 | return novelDao.getNovelByRecentL23(sqlSession); 59 | } 60 | 61 | public List> getNovelByScoreL10() { 62 | return novelDao.getNovelByScoreL10(sqlSession); 63 | } 64 | 65 | public List> getNovelByScoreL17() { 66 | return novelDao.getNovelByScoreL17(sqlSession); 67 | } 68 | 69 | public List> getScoreNovelByLid(int lid) { 70 | return novelDao.getScoreNovelByLid(sqlSession, lid); 71 | } 72 | 73 | public List> getNovelByNewL10() { 74 | return novelDao.getNovelByNewL10(sqlSession); 75 | } 76 | 77 | public List> getNovelByNewL17() { 78 | return novelDao.getNovelByNewL17(sqlSession); 79 | } 80 | 81 | public List> getNovelByClickL10() { 82 | return novelDao.getNovelByClickL10(sqlSession); 83 | } 84 | 85 | public NovelEntity getNovelByTitle(String title) { 86 | return novelDao.getNovelByTitle(sqlSession ,title); 87 | } 88 | 89 | public List> getNovelByLidRecent(int lid) { 90 | return novelDao.getNovelByLidRecent(sqlSession, lid); 91 | } 92 | 93 | public List> getNovelByLidScore(int lid) { 94 | return novelDao.getNovelByLidScore(sqlSession, lid); 95 | } 96 | 97 | public List> getNovelByStateL10(int state) { 98 | return novelDao.getNovelByStateL10(sqlSession, state); 99 | } 100 | 101 | public List> getNovelInBookCase(BookCaseEntity bookCaseEntity) { 102 | return novelDao.getNovelInBookCase(sqlSession, bookCaseEntity); 103 | } 104 | 105 | public List> searchNovelInBookCase(Map map) { 106 | return novelDao.getInBookCaseByTitle(sqlSession, map); 107 | } 108 | 109 | 110 | public Map getNovelByRecord(RecordEntity recordEntity) { 111 | return novelDao.getNovelByRecord(sqlSession, recordEntity); 112 | } 113 | 114 | public List> search(Map map) { 115 | List> novels = novelDao.getNovelByTitleWidly(sqlSession, map); 116 | if (novels.size() == 0) { 117 | novels = novelDao.getNovelByAuthorName(sqlSession, map.get("key").toString()); 118 | } 119 | return novels; 120 | } 121 | 122 | public List> getNovelByAuthorName(String authorName) { 123 | return novelDao.getNovelByAuthorName(sqlSession, authorName); 124 | } 125 | 126 | public List> getNotAllowedNovel() { 127 | return novelDao.getNotAllowedNovel(sqlSession); 128 | } 129 | 130 | public List> getNovelByRecommendL10() { 131 | return novelDao.getNovelByRecommendL10(sqlSession); 132 | } 133 | 134 | public List getEditNovel() { 135 | return novelDao.getEditNovel(sqlSession); 136 | } 137 | 138 | public List> getNewNovelByLid(int lid) { 139 | return novelDao.getNewNovelByLid(sqlSession, lid); 140 | } 141 | 142 | public List> getNewNovelByLidL10(int lid) { 143 | return novelDao.getNewNovelByLidL10(sqlSession, lid); 144 | } 145 | 146 | public List> getNewNovelByLidL23(int lid) { 147 | return novelDao.getNewNovelByLidL23(sqlSession, lid); 148 | } 149 | 150 | public List> getPopularNovelByLid(int lid) { 151 | return novelDao.getPopularNovelByLid(sqlSession, lid); 152 | } 153 | 154 | public List> getPopularNovelByLidL10(int lid) { 155 | return novelDao.getPopularNovelByLidL10(sqlSession, lid); 156 | } 157 | 158 | public List> getUpdateNovelByLid(int lid) { 159 | return novelDao.getUpdateNovelByLid(sqlSession, lid); 160 | } 161 | 162 | public List> getFinishNovelByLid(Map m) { 163 | return novelDao.getFinishNovelByLid(sqlSession, m); 164 | } 165 | 166 | public List> getFinishNovelByLidL10(int lid) { 167 | return novelDao.getFinishNovelByLidL10(sqlSession, lid); 168 | } 169 | 170 | 171 | public List> getRecommendNovelByLid(int lid) { 172 | return novelDao.getRecommendNovelByLid(sqlSession, lid); 173 | } 174 | 175 | public List> getRecommendNovelByLidL10(int lid) { 176 | return novelDao.getRecommendNovelByLidL10(sqlSession, lid); 177 | } 178 | 179 | public List> getRecommendNovelByLidL15(int lid) { 180 | return novelDao.getRecommendNovelByLidL15(sqlSession, lid); 181 | } 182 | 183 | public List> getCollectNovelByLid(int lid) { 184 | return novelDao.getCollectNovelByLid(sqlSession, lid); 185 | } 186 | 187 | public List> getCollectNovelByLidL10(int lid) { 188 | return novelDao.getCollectNovelByLidL10(sqlSession, lid); 189 | } 190 | 191 | public List> getClickNovelByLid(int lid) { 192 | return novelDao.getClickNovelByLid(sqlSession, lid); 193 | } 194 | 195 | public List> getClickNovelByLidL10(int lid) { 196 | return novelDao.getClickNovelByLidL10(sqlSession, lid); 197 | } 198 | 199 | public List> getAllNovelByLid(int lid) { 200 | return novelDao.getAllNovelByLid(sqlSession, lid); 201 | } 202 | 203 | public List> searchNovel(String bookName) { 204 | return novelDao.getNovelByBookName(sqlSession, bookName); 205 | } 206 | 207 | public boolean addChapterNum(Long nid) { 208 | return novelDao.addChapterNum(sqlSession, nid); 209 | } 210 | 211 | public Boolean updateScore(Map map) { 212 | return novelDao.updateScore(sqlSession, map); 213 | } 214 | 215 | public List> getNovelByUid(int uid) { 216 | return novelDao.getNovelByUid(sqlSession, uid); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/BookCaseController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.riyeyuedu.entity.BookCaseEntity; 4 | import com.riyeyuedu.entity.RecordEntity; 5 | import com.riyeyuedu.entity.ResponseEntity; 6 | import com.riyeyuedu.service.BookCaseService; 7 | import com.riyeyuedu.service.NovelService; 8 | import com.riyeyuedu.service.RecordService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.transaction.annotation.Transactional; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.HashMap; 14 | import java.util.LinkedList; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | @RestController 19 | public class BookCaseController { 20 | private BookCaseService bookCaseService; 21 | 22 | private NovelService novelService; 23 | 24 | private RecordService recordService; 25 | 26 | @Autowired 27 | public void setNovelService(NovelService novelService) { 28 | this.novelService = novelService; 29 | } 30 | 31 | @Autowired 32 | public void setBookCaseService(BookCaseService bookCaseService) { 33 | this.bookCaseService = bookCaseService; 34 | } 35 | 36 | @Autowired 37 | public void setRecordService(RecordService recordService) { 38 | this.recordService = recordService; 39 | } 40 | 41 | @RequestMapping(value = "/user/addBookcase/{uid}/{type}") 42 | @CrossOrigin 43 | public ResponseEntity addBookCase(@PathVariable int uid, @PathVariable String type) { 44 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 45 | bookCaseEntity.setUid(uid); 46 | bookCaseEntity.setType(type); 47 | 48 | if (bookCaseService.getBookCase(bookCaseEntity) != null) { 49 | return new ResponseEntity(400, "已存在同名类别的书架", null); 50 | } 51 | 52 | return new ResponseEntity(bookCaseService.addBookCase(bookCaseEntity)); 53 | } 54 | 55 | @RequestMapping(value = "/user/addToBookCase/{uid}/{nid}/{type}") 56 | @CrossOrigin 57 | @Transactional 58 | public ResponseEntity addToBookCase(@PathVariable Long nid, @PathVariable int uid, @PathVariable String type) { 59 | BookCaseEntity bookCase = new BookCaseEntity(); 60 | bookCase.setUid(uid); 61 | bookCase.setType(type); 62 | 63 | Long bid = bookCaseService.getBookCase(bookCase).getBid(); 64 | 65 | Map map = new HashMap<>(); 66 | map.put("bid", bid); 67 | map.put("nid", nid); 68 | 69 | if (bookCaseService.isNovelInBookcase(map) == null) { 70 | bookCaseService.addNovelToBookcase(map); 71 | return new ResponseEntity("加入成功"); 72 | } else { 73 | return new ResponseEntity(400, "已存在于书架", null); 74 | } 75 | } 76 | 77 | @RequestMapping(value = "/user/bookcase/{uid}/{type}") 78 | @ResponseBody 79 | @CrossOrigin 80 | public ResponseEntity getNovelInBookcase(@PathVariable int uid, @PathVariable String type) { 81 | System.out.println(uid + ";" + type); 82 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 83 | bookCaseEntity.setUid(uid); 84 | bookCaseEntity.setType(type); 85 | 86 | Long bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 87 | System.out.println(bid); 88 | 89 | Map map = new HashMap<>(); 90 | List> novelMap = novelService.getNovelInBookCase(bookCaseEntity); 91 | System.out.println(novelMap); 92 | 93 | RecordEntity recordEntity; 94 | 95 | Map temp; 96 | 97 | for (Map novel : novelMap) { 98 | Long nid = (Long) novel.get("nid"); 99 | recordEntity = new RecordEntity(); 100 | recordEntity.setUid(uid); 101 | recordEntity.setNid(nid); 102 | recordEntity = recordService.getRecord(recordEntity); 103 | System.out.println(recordEntity); 104 | 105 | if (recordEntity != null) { 106 | temp = recordService.getRecordDetail(recordEntity); 107 | Long cid = (Long) temp.get("record_cid"); 108 | String chapterName = (String) temp.get("record_chapter_name"); 109 | novel.put("record_cid", cid); 110 | novel.put("record_chapter_name", chapterName); 111 | } else { 112 | novel.put("record_cid", -1); 113 | novel.put("record_chapter_name", "-1"); 114 | } 115 | } 116 | 117 | map.put("novel", novelMap); 118 | map.put("num", bookCaseService.getNovelCount(bid).get("num")); 119 | return new ResponseEntity(map); 120 | } 121 | 122 | @RequestMapping(value = "/bookcase/recent/{uid}") 123 | @CrossOrigin 124 | public ResponseEntity getNovelByRecent(@PathVariable int uid) { 125 | List> recordList = recordService.getAllRecordDetail(uid); 126 | 127 | Map temp; 128 | 129 | List> novelList = new LinkedList<>(); 130 | 131 | RecordEntity recordEntity; 132 | 133 | for (Map record : recordList) { 134 | recordEntity = new RecordEntity(); 135 | recordEntity.setNid((Long) record.get("nid")); 136 | recordEntity.setUid(uid); 137 | temp = novelService.getNovelByRecord(recordEntity); 138 | temp.put("record_cid", record.get("record_cid")); 139 | temp.put("record_chapter_name", record.get("record_chapter_name")); 140 | novelList.add(temp); 141 | } 142 | 143 | return new ResponseEntity(novelList); 144 | } 145 | 146 | @RequestMapping(value = "/user/deleteNovelInBookcase/{uid}/{nid}/{type}") 147 | @CrossOrigin 148 | public ResponseEntity deleteNovelInBookcase(@PathVariable int uid, @PathVariable Long nid, @PathVariable String type) { 149 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 150 | bookCaseEntity.setUid(uid); 151 | bookCaseEntity.setType(type); 152 | Long bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 153 | 154 | Map map = new HashMap<>(); 155 | map.put("bid", bid); 156 | map.put("nid", nid); 157 | 158 | if (bookCaseService.isNovelInBookcase(map) == null) { 159 | return new ResponseEntity(400, "书架中不存在此书", null); 160 | } else { 161 | bookCaseService.deleteNovelInBookCase(map); 162 | return new ResponseEntity("删除成功"); 163 | } 164 | } 165 | 166 | @RequestMapping(value = "/allBookcase/{uid}") 167 | @CrossOrigin 168 | public ResponseEntity getAllBookcase(@PathVariable int uid) { 169 | return new ResponseEntity(bookCaseService.getAllBookcase(uid)); 170 | } 171 | 172 | @RequestMapping(value = "/removeBookcase/{uid}/{nid}/{type}") 173 | @CrossOrigin 174 | public ResponseEntity removeBookcase(@PathVariable int uid, @PathVariable Long nid, @PathVariable String type) { 175 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 176 | bookCaseEntity.setUid(uid); 177 | bookCaseEntity.setType(type); 178 | 179 | Long bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 180 | 181 | Map map = new HashMap<>(); 182 | map.put("bid", bid); 183 | map.put("nid", nid); 184 | 185 | return new ResponseEntity(bookCaseService.removeBookcase(map)); 186 | } 187 | 188 | @RequestMapping(value = "/user/toTop/{uid}/{nid}/{type}/{level}") 189 | @CrossOrigin 190 | public ResponseEntity toTop(@PathVariable int uid, @PathVariable Long nid, @PathVariable String type, @PathVariable int level) { 191 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 192 | bookCaseEntity.setUid(uid); 193 | bookCaseEntity.setType(type); 194 | 195 | Long bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 196 | 197 | Map map = new HashMap<>(); 198 | map.put("bid", bid); 199 | map.put("nid", nid); 200 | map.put("level", level); 201 | 202 | return new ResponseEntity(bookCaseService.toTop(map)); 203 | } 204 | 205 | @RequestMapping(value = "/user/topNum/{uid}/{type}") 206 | @CrossOrigin 207 | public ResponseEntity getTopNum(@PathVariable int uid, @PathVariable String type) { 208 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 209 | bookCaseEntity.setUid(uid); 210 | bookCaseEntity.setType(type); 211 | 212 | Long bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 213 | System.out.println(bid); 214 | 215 | return new ResponseEntity(bookCaseService.getTopNum(bid)); 216 | } 217 | 218 | @RequestMapping(value = "/cancelTop/{uid}/{nid}/{type}") 219 | @CrossOrigin 220 | public ResponseEntity cancelTop(@PathVariable int uid, @PathVariable Long nid, @PathVariable String type) { 221 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 222 | bookCaseEntity.setUid(uid); 223 | bookCaseEntity.setType(type); 224 | 225 | Long bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 226 | 227 | Map map = new HashMap<>(); 228 | map.put("bid", bid); 229 | map.put("nid", nid); 230 | 231 | return new ResponseEntity(bookCaseService.updateLevelDown(map)); 232 | } 233 | 234 | @RequestMapping(value = "/deleteBookcase/{uid}/{type}") 235 | @CrossOrigin 236 | public ResponseEntity deleteBookcase(@PathVariable int uid, @PathVariable String type) { 237 | Long bid = bookCaseService.getDefaultBookcase(uid).getBid(); 238 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 239 | bookCaseEntity.setType(type); 240 | bookCaseEntity.setUid(uid); 241 | List> list = novelService.getNovelInBookCase(bookCaseEntity); 242 | Map novel; 243 | for (Map map : list) { 244 | novel = new HashMap<>(); 245 | novel.put("nid", map.get("nid")); 246 | novel.put("bid", bid); 247 | bookCaseService.removeBookcase(novel); 248 | } 249 | 250 | bid = bookCaseService.getBookCase(bookCaseEntity).getBid(); 251 | 252 | return new ResponseEntity(bookCaseService.deleteBookcase(bid)); 253 | } 254 | 255 | @RequestMapping(value = "/searchInBookcase/{uid}/{title}") 256 | @CrossOrigin 257 | public ResponseEntity searchNovel(@PathVariable int uid, @PathVariable String title) { 258 | Map map = new HashMap<>(); 259 | map.put("uid", uid); 260 | map.put("title", title); 261 | return new ResponseEntity(novelService.searchNovelInBookCase(map)); 262 | } 263 | } 264 | 265 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.aliyun.oss.ClientConfiguration; 4 | import com.aliyun.oss.OSSClient; 5 | import com.riyeyuedu.controller.Format.IndexLoginFormat; 6 | import com.riyeyuedu.controller.Format.IndexRegisterFormat; 7 | import com.riyeyuedu.entity.BookCaseEntity; 8 | import com.riyeyuedu.entity.ResponseEntity; 9 | import com.riyeyuedu.entity.UserEntity; 10 | import com.riyeyuedu.service.BookCaseService; 11 | import com.riyeyuedu.service.RedisService; 12 | import com.riyeyuedu.service.UserService; 13 | import com.riyeyuedu.util.JWTUtil; 14 | import com.riyeyuedu.util.SmsUtil; 15 | import org.apache.shiro.authz.UnauthorizedException; 16 | import org.apache.shiro.authz.annotation.RequiresAuthentication; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.web.bind.annotation.*; 19 | import org.springframework.web.multipart.MultipartFile; 20 | 21 | import java.io.InputStream; 22 | import java.text.SimpleDateFormat; 23 | import java.util.Date; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.Random; 27 | 28 | @RestController 29 | public class UserController { 30 | private UserService userService; 31 | 32 | private RedisService redisService; 33 | 34 | private BookCaseService bookCaseService; 35 | 36 | private String code; 37 | 38 | public String getCode() { 39 | return code; 40 | } 41 | 42 | public void setCode(String code) { 43 | this.code = code; 44 | } 45 | 46 | @Autowired 47 | public void setUserService(UserService userService) { 48 | this.userService = userService; 49 | } 50 | 51 | @Autowired 52 | public void setRedisService(RedisService redisService) { 53 | this.redisService = redisService; 54 | } 55 | 56 | @Autowired 57 | public void setBookCaseService(BookCaseService bookCaseService) { 58 | this.bookCaseService = bookCaseService; 59 | } 60 | 61 | @RequestMapping(value = "/checkReader", method = RequestMethod.POST) 62 | @CrossOrigin 63 | public ResponseEntity checkReader(@RequestBody IndexRegisterFormat format) { 64 | if (userService.getUserByPhone(format.getPhone()) != null) { 65 | return new ResponseEntity(200, "用户存在", null); 66 | } else { 67 | return new ResponseEntity(400, "用户不存在", null); 68 | } 69 | } 70 | 71 | @RequestMapping(value = "/editPassword", method = RequestMethod.POST) 72 | @CrossOrigin 73 | public ResponseEntity changePassword(@RequestBody IndexRegisterFormat format) { 74 | if (userService.getUserByPhone(format.getPhone()) != null) { 75 | UserEntity userEntity = new UserEntity(); 76 | userEntity.setPhone(format.getPhone()); 77 | userEntity.setPassword(format.getPassword()); 78 | Boolean isChange = userService.changePassword(userEntity); 79 | return new ResponseEntity(isChange ? 200 : 400, "", isChange); 80 | } else { 81 | return new ResponseEntity(400, "修改失败", null); 82 | } 83 | } 84 | 85 | @RequestMapping(value = "/user/editAvatar/{uid}", method = RequestMethod.POST) 86 | @CrossOrigin 87 | public ResponseEntity editAvatar(@RequestBody MultipartFile file, @PathVariable int uid) { 88 | Date day=new Date(); 89 | 90 | SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); 91 | 92 | String fileName = file.getOriginalFilename(); 93 | String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); 94 | 95 | String avatar = df.format(day) + "." + suffix; 96 | 97 | String portrait = userService.getPortraitByUid(uid); 98 | 99 | String oldAvatar = portrait.substring(portrait.lastIndexOf("/") + 1); 100 | try { 101 | ClientConfiguration config = new ClientConfiguration(); 102 | config.setConnectionTimeout(1000); 103 | config.setMaxErrorRetry(1); 104 | 105 | // endpoint以杭州为例,其它region请按实际情况填写 106 | String endpoint = "http://oss-cn-beijing.aliyuncs.com"; 107 | // 云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用RAM子账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建 108 | String accessKeyId = "LTAICBaKv7FrgzZf"; 109 | String accessKeySecret = "0CWhs6GjKdOqhGWNxZod3jM1npFdE7"; 110 | // 创建OSSClient实例 111 | OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); 112 | // 上传文件流 113 | InputStream inputStream = file.getInputStream(); 114 | 115 | ossClient.putObject("nealcaffrey", "avatar/" + avatar, inputStream); 116 | 117 | if(!portrait.contains("default")) { 118 | // 删除Object 119 | ossClient.deleteObject("nealcaffrey", "avatar/" + oldAvatar); 120 | } 121 | 122 | ossClient.shutdown(); 123 | } catch (Exception e) { 124 | System.out.println(e.getMessage()); 125 | } 126 | 127 | 128 | // 关闭client 129 | 130 | avatar = "http://nealcaffrey.oss-cn-beijing.aliyuncs.com/avatar/" + avatar; 131 | 132 | UserEntity userEntity = new UserEntity(); 133 | userEntity.setPortrait(avatar); 134 | userEntity.setUid(uid); 135 | 136 | userService.updateAvatar(userEntity); 137 | return new ResponseEntity(avatar); 138 | } 139 | 140 | @RequestMapping(value = "/user/home", method = RequestMethod.GET) 141 | @CrossOrigin 142 | @RequiresAuthentication 143 | public ResponseEntity getPerson() { 144 | return new ResponseEntity(200, "you coming", null); 145 | } 146 | 147 | @RequestMapping(value = "/login", method = RequestMethod.POST) 148 | @CrossOrigin 149 | public Map login(@RequestBody IndexLoginFormat format) { 150 | UserEntity userEntity; 151 | if (format.getUsername().length() != 11) { 152 | userEntity = userService.getReaderByName(format.getUsername()); 153 | } else { 154 | userEntity = userService.getUserByPhone(format.getUsername()); 155 | } 156 | 157 | if (userEntity != null) { 158 | if (userEntity.getPassword().equals(format.getPassword())) { 159 | Map map = new HashMap<>(); 160 | map.put("msg", "Login success"); 161 | map.put("code", "200"); 162 | map.put("token", JWTUtil.sign(userEntity.getUsername(), userEntity.getPassword())); 163 | map.put("uid", String.valueOf(userEntity.getUid())); 164 | map.put("username", userEntity.getUsername()); 165 | return map; 166 | } else { 167 | throw new UnauthorizedException(); 168 | } 169 | } else { 170 | throw new UnauthorizedException(); 171 | } 172 | } 173 | 174 | @RequestMapping(value = "/checkPhone", method = RequestMethod.POST) 175 | @CrossOrigin 176 | public ResponseEntity checkPhone(@RequestBody IndexRegisterFormat format) { 177 | if (userService.getUserByPhone(format.getPhone()) == null) { 178 | return new ResponseEntity("手机号可用"); 179 | } else { 180 | return new ResponseEntity(400, "手机号已被注册", "null"); 181 | } 182 | } 183 | 184 | @RequestMapping(value = "/checkUsername", method = RequestMethod.POST) 185 | @CrossOrigin 186 | public ResponseEntity checkUsername(@RequestBody IndexRegisterFormat format) { 187 | if (userService.getUserByUsername(format.getUsername()) == null) { 188 | return new ResponseEntity("用户名可用"); 189 | }else { 190 | return new ResponseEntity(400, "用户名已被注册", "null"); 191 | } 192 | } 193 | 194 | @RequestMapping(value = "/register", method = RequestMethod.POST) 195 | @CrossOrigin 196 | public ResponseEntity register(@RequestBody IndexRegisterFormat format) { 197 | UserEntity userEntity = new UserEntity(); 198 | userEntity.setUsername(format.getUsername()); 199 | userEntity.setPassword(format.getPassword()); 200 | userEntity.setPortrait("http://nealcaffrey.oss-cn-beijing.aliyuncs.com/avatar/default.jpg"); 201 | userEntity.setPhone(format.getPhone()); 202 | 203 | userService.register(userEntity); 204 | 205 | /*新增,待测试*/ 206 | BookCaseEntity bookCaseEntity = new BookCaseEntity(); 207 | bookCaseEntity.setUid(userService.getUserByPhone(userEntity.getPhone()).getUid()); 208 | bookCaseEntity.setType("默认分组"); 209 | bookCaseService.addBookCase(bookCaseEntity); 210 | 211 | return new ResponseEntity("注册成功"); 212 | } 213 | 214 | @RequestMapping(value = "/getCode", method = RequestMethod.POST) 215 | @CrossOrigin 216 | public ResponseEntity getCode(@RequestBody IndexRegisterFormat format) { 217 | //产生随机数 218 | Random random = new Random(); 219 | String result=""; 220 | for (int i=0;i<6;i++) 221 | { 222 | result += random.nextInt(10); 223 | } 224 | 225 | setCode(result); 226 | 227 | if (!redisService.exists(format.getPhone())) { 228 | redisService.set(format.getPhone(), true, 60L); 229 | return SmsUtil.sendSms(result, format.getPhone()); 230 | } else { 231 | return new ResponseEntity(400, "请求过于频繁,请稍后再试", null); 232 | } 233 | } 234 | 235 | @RequestMapping(value = "/checkCode", method = RequestMethod.POST) 236 | @CrossOrigin 237 | public ResponseEntity checkCode(@RequestBody IndexRegisterFormat format) { 238 | if (getCode().equals(format.getCode())) { 239 | return new ResponseEntity("验证码正确"); 240 | } else { 241 | return new ResponseEntity(400, "验证码输入错误", null); 242 | } 243 | } 244 | 245 | @RequestMapping(value = "/updateInfo", method = RequestMethod.POST) 246 | @CrossOrigin 247 | public ResponseEntity updateInfo(@RequestBody UserEntity userEntity) { 248 | return new ResponseEntity(userService.updateInfo(userEntity)); 249 | } 250 | 251 | @RequestMapping(value = "/user/info/{uid}", method = RequestMethod.GET) 252 | @CrossOrigin 253 | public ResponseEntity getUserInfo(@PathVariable int uid) { 254 | Map map = new HashMap<>(); 255 | map.put("info", userService.getInfoByUid(uid)); 256 | map.put("bookNum", bookCaseService.getBookNumByUid(uid)); 257 | return new ResponseEntity(map); 258 | } 259 | 260 | @RequestMapping(value = "/user/portrait/{uid}") 261 | @CrossOrigin 262 | public ResponseEntity getUserPortrait(@PathVariable int uid) { 263 | return new ResponseEntity(userService.getPortraitByUid(uid)); 264 | } 265 | 266 | @RequestMapping(value = "/otherUser/{uid}") 267 | @CrossOrigin 268 | public ResponseEntity getOtherInfo(@PathVariable int uid) { 269 | return new ResponseEntity(userService.getInfoByUid(uid)); 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/dao/NovelDao.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.dao; 2 | 3 | import com.riyeyuedu.entity.BookCaseEntity; 4 | import com.riyeyuedu.entity.NovelEntity; 5 | import com.riyeyuedu.entity.RecordEntity; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.session.SqlSession; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created by 阳溢 on 2018/1/5. 16 | */ 17 | @Repository 18 | public class NovelDao { 19 | 20 | public boolean addNovel(SqlSession sqlSession, NovelEntity novel) { 21 | int insertNum = sqlSession.insert("novel.insertNovel", novel); 22 | return insertNum == 1; 23 | } 24 | 25 | public Map getNovelByNid(SqlSession sqlSession, long nid) { 26 | return sqlSession.selectOne("novel.getNovelByNid", nid); 27 | } 28 | 29 | public Map getTitleByNid(SqlSession sqlSession, Long nid) { 30 | return sqlSession.selectOne("novel.getTitleByNid", nid); 31 | } 32 | 33 | public List> getNovelByStateL10(SqlSession sqlSession, int state) { 34 | return sqlSession.selectList("novel.getNovelByStateL10", state); 35 | } 36 | 37 | public List> getAllNovel(SqlSession sqlSession, Map map) { 38 | return sqlSession.selectList("novel.getAllNovel", map); 39 | } 40 | 41 | public void addClickNum (SqlSession sqlSession, long nid) { 42 | sqlSession.update("novel.addClickNum", nid); 43 | } 44 | 45 | public List> getNovelByLidL5(SqlSession sqlSession, int lid) { 46 | return sqlSession.selectList("novel.getNovelByLidL5", lid); 47 | } 48 | 49 | public List> getNovelByRecentL23(SqlSession sqlSession) { 50 | return sqlSession.selectList("novel.getNovelByRecentL23"); 51 | } 52 | 53 | public List> getNovelByScoreL10(SqlSession sqlSession) { 54 | return sqlSession.selectList("novel.getNovelByScoreL10"); 55 | } 56 | 57 | public List> getNovelByScoreL17(SqlSession sqlSession) { 58 | return sqlSession.selectList("novel.getNovelByScoreL17"); 59 | } 60 | 61 | public List> getScoreNovelByLid(SqlSession sqlSession, int lid) { 62 | if (lid == 0) { 63 | return sqlSession.selectList("novel.getScoreNovel"); 64 | } else { 65 | return sqlSession.selectList("novel.getScoreNovelByLid", lid); 66 | } 67 | 68 | } 69 | 70 | public List> getNovelByNewL10(SqlSession sqlSession) { 71 | return sqlSession.selectList("novel.getNovelByNewL10"); 72 | } 73 | 74 | public List> getNovelByNewL17(SqlSession sqlSession) { 75 | return sqlSession.selectList("novel.getNovelByNewL17"); 76 | } 77 | 78 | public List> getNovelByClickL10(SqlSession sqlSession) { 79 | return sqlSession.selectList("novel.getNovelByClickL10"); 80 | } 81 | 82 | public NovelEntity getNovelByTitle(SqlSession sqlSession, String title) { 83 | return sqlSession.selectOne("novel.getNovelByTitle", title); 84 | } 85 | 86 | public List> getNovelByLidRecent(SqlSession sqlSession, int lid) { 87 | return sqlSession.selectList("novel.getNovelByLidRecent", lid); 88 | } 89 | 90 | public List> getNovelByLidScore(SqlSession sqlSession, int lid) { 91 | return sqlSession.selectList("novel.getNovelByLidScore", lid); 92 | } 93 | 94 | public List> getNovelInBookCase(SqlSession sqlSession, BookCaseEntity bookCaseEntity) { 95 | return sqlSession.selectList("novel.getNovelInBookCase", bookCaseEntity); 96 | } 97 | 98 | public List> getInBookCaseByTitle(SqlSession sqlSession, Map map) { 99 | return sqlSession.selectList("novel.getInBookcaseByTitle", map); 100 | } 101 | 102 | public Map getNovelByRecord(SqlSession sqlSession, RecordEntity recordEntity) { 103 | return sqlSession.selectOne("novel.getNovelByRecord", recordEntity); 104 | } 105 | 106 | public List> getNovelByTitleWidly(SqlSession sqlSession, Map map) { 107 | return sqlSession.selectList("novel.getNovelByTitleWidly", map); 108 | } 109 | 110 | public List> getNovelByAuthorName(SqlSession sqlSession, String authorName) { 111 | return sqlSession.selectList("novel.getNovelByAuthor", authorName); 112 | } 113 | 114 | public NovelEntity getOneInBookCase(SqlSession sqlSession, BookCaseEntity bookCase) { 115 | return sqlSession.selectOne("novel.getOneInBookCase", bookCase); 116 | } 117 | 118 | public List> getNotAllowedNovel(SqlSession sqlSession) { 119 | return sqlSession.selectList("novel.getNotAllowedNovel"); 120 | } 121 | 122 | public List> getNovelByRecommendL10(SqlSession sqlSession) { 123 | return sqlSession.selectList("novel.getNovelByRecommendL10"); 124 | } 125 | 126 | public List> getNewNovelByLid(SqlSession sqlSession, int lid) { 127 | if (lid == 0) { 128 | return sqlSession.selectList("novel.getNewNovel"); 129 | } else { 130 | return sqlSession.selectList("novel.getNewNovelByLid", lid); 131 | } 132 | } 133 | 134 | public List> getNewNovelByLidL10(SqlSession sqlSession, int lid) { 135 | if (lid == 0) { 136 | return sqlSession.selectList("novel.getNewNovelL10"); 137 | } else { 138 | return sqlSession.selectList("novel.getNewNovelByLidL10", lid); 139 | } 140 | } 141 | 142 | public List> getNewNovelByLidL23(SqlSession sqlSession, int lid) { 143 | if (lid == 0) { 144 | return sqlSession.selectList("novel.getNewNovelL23"); 145 | } else { 146 | return sqlSession.selectList("novel.getNewNovelByLidL23", lid); 147 | } 148 | } 149 | 150 | public List> getPopularNovelByLid(SqlSession sqlSession, int lid) { 151 | if (lid == 0) { 152 | return sqlSession.selectList("novel.getPopularNovel"); 153 | } else { 154 | return sqlSession.selectList("novel.getPopularNovelByLid", lid); 155 | } 156 | } 157 | 158 | public List> getPopularNovelByLidL10(SqlSession sqlSession, int lid) { 159 | if (lid == 0) { 160 | return sqlSession.selectList("novel.getPopularNovelL10"); 161 | } else { 162 | return sqlSession.selectList("novel.getPopularNovelByLidL10", lid); 163 | } 164 | } 165 | 166 | public List> getUpdateNovelByLid(SqlSession sqlSession, int lid) { 167 | return sqlSession.selectList("novel.getUpdateNovelByLid", lid); 168 | } 169 | 170 | public List> getFinishNovelByLid(SqlSession sqlSession, Map m) { 171 | if ((int) m.get("lid") == 0) { 172 | return sqlSession.selectList("novel.getFinishNovel", m); 173 | } else { 174 | return sqlSession.selectList("novel.getFinishNovelByLid", m); 175 | } 176 | } 177 | 178 | public List> getFinishNovelByLidL10(SqlSession sqlSession, int lid) { 179 | if (lid == 0) { 180 | return sqlSession.selectList("novel.getFinishNovelL10"); 181 | } else { 182 | return sqlSession.selectList("novel.getFinishNovelByLidL10", lid); 183 | } 184 | } 185 | 186 | public List> getRecommendNovelByLid(SqlSession sqlSession, int lid) { 187 | if (lid == 0) { 188 | return sqlSession.selectList("novel.getRecommendNovel"); 189 | } else { 190 | return sqlSession.selectList("novel.getRecommendNovelByLid", lid); 191 | } 192 | } 193 | 194 | public List> getRecommendNovelByLidL10(SqlSession sqlSession, int lid) { 195 | if (lid == 0) { 196 | return sqlSession.selectList("novel.getRecommendNovelL10"); 197 | } else { 198 | return sqlSession.selectList("novel.getRecommendNovelByLidL10", lid); 199 | } 200 | } 201 | 202 | public List> getRecommendNovelByLidL15(SqlSession sqlSession, int lid) { 203 | if (lid == 0) { 204 | return sqlSession.selectList("novel.getRecommendNovelL15"); 205 | } else { 206 | return sqlSession.selectList("novel.getRecommendNovelByLidL15", lid); 207 | } 208 | } 209 | 210 | public List> getClickNovelByLid(SqlSession sqlSession, int lid) { 211 | if (lid == 0) { 212 | return sqlSession.selectList("novel.getClickNovel"); 213 | } else { 214 | return sqlSession.selectList("novel.getClickNovelByLid", lid); 215 | } 216 | } 217 | 218 | public List> getClickNovelByLidL10(SqlSession sqlSession, int lid) { 219 | if (lid == 0) { 220 | return sqlSession.selectList("novel.getClickNovelL10"); 221 | } else { 222 | return sqlSession.selectList("novel.getClickNovelByLidL10", lid); 223 | } 224 | } 225 | 226 | public List getEditNovel(SqlSession sqlSession) { 227 | return sqlSession.selectList("novel.getEditNovel"); 228 | } 229 | 230 | public List> getCollectNovelByLid(SqlSession sqlSession, int lid) { 231 | if (lid == 0) { 232 | return sqlSession.selectList("novel.getCollectNovel"); 233 | } else { 234 | return sqlSession.selectList("novel.getCollectNovelByLid", lid); 235 | } 236 | } 237 | 238 | public List> getCollectNovelByLidL10(SqlSession sqlSession, int lid) { 239 | if (lid == 0) { 240 | return sqlSession.selectList("novel.getCollectNovelL10"); 241 | } else { 242 | return sqlSession.selectList("novel.getCollectNovelByLidL10", lid); 243 | } 244 | } 245 | 246 | public List> getAllNovelByLid(SqlSession sqlSession, int lid) { 247 | return sqlSession.selectList("novel.getAllNovelByLid", lid); 248 | } 249 | 250 | public List> getNovelByBookName(SqlSession sqlSession, String bookName) { 251 | return sqlSession.selectList("novel.getNovelByBookName", bookName); 252 | } 253 | 254 | public boolean addChapterNum(SqlSession sqlSession, Long nid) { 255 | int updateNum = sqlSession.update("novel.addChapterNum", nid); 256 | return updateNum == 1; 257 | } 258 | 259 | public Boolean updateScore(SqlSession sqlSession, Map map) { 260 | int updateNum = sqlSession.update("novel.updateScore", map); 261 | return updateNum == 1; 262 | } 263 | 264 | public List> getNovelByUid(SqlSession sqlSession, int uid) { 265 | return sqlSession.selectList("novel.getNovelByUid", uid); 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /src/main/java/com/riyeyuedu/controller/NovelController.java: -------------------------------------------------------------------------------- 1 | package com.riyeyuedu.controller; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import com.riyeyuedu.entity.*; 6 | import com.riyeyuedu.service.*; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.Date; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * Created by 阳溢 on 2018/1/5. 17 | */ 18 | @RestController 19 | public class NovelController { 20 | private NovelService novelService; 21 | 22 | private ScoreService scoreService; 23 | 24 | @Autowired 25 | public void setNovelService(NovelService novelService) { 26 | this.novelService = novelService; 27 | } 28 | 29 | @Autowired 30 | public void setScoreService(ScoreService scoreService) { 31 | this.scoreService = scoreService; 32 | } 33 | 34 | @RequestMapping(method = RequestMethod.GET, path = "/") 35 | @CrossOrigin 36 | public Map>> getAllNovel() { 37 | 38 | Map>> novels = new HashMap<>(); 39 | novels.put("scoreNovels", novelService.getNovelByScoreL17()); 40 | novels.put("newNovels", novelService.getNovelByNewL17()); 41 | novels.put("classNovels1", novelService.getNovelByLidL5(1)); 42 | novels.put("classNovels2", novelService.getNovelByLidL5(2)); 43 | novels.put("classNovels3", novelService.getNovelByLidL5(3)); 44 | novels.put("classNovels4", novelService.getNovelByLidL5(4)); 45 | novels.put("classNovels5", novelService.getNovelByLidL5(5)); 46 | novels.put("classNovels6", novelService.getNovelByLidL5(6)); 47 | novels.put("classNovels7", novelService.getNovelByLidL5(7)); 48 | 49 | return novels; 50 | } 51 | 52 | @RequestMapping(value = "/novel/complete", method = RequestMethod.GET) 53 | @CrossOrigin 54 | public List> getCompleteNovel() { 55 | 56 | return novelService.getNovelByStateL10(1); 57 | } 58 | 59 | @RequestMapping(value = "/novel/recommend") 60 | @CrossOrigin 61 | public List> getNovelByRecommend() { 62 | return novelService.getNovelByRecommendL10(); 63 | } 64 | 65 | @RequestMapping(value = "/novel/new") 66 | @CrossOrigin 67 | public List> getNovelByNew() { 68 | return novelService.getNovelByNewL10(); 69 | } 70 | 71 | @RequestMapping(value = "/novel/collect") 72 | @CrossOrigin 73 | public List> getNovelByCollectNum() { 74 | return novelService.getCollectNovelByLid(0); 75 | } 76 | 77 | @RequestMapping(value = "/novel/click") 78 | @CrossOrigin 79 | public List> getNovelByClick() { 80 | return novelService.getNovelByClickL10(); 81 | } 82 | 83 | @RequestMapping(value = "/novel/recent") 84 | @CrossOrigin 85 | public List> getNovelByRecent() { 86 | return novelService.getNovelByRecentL23(); 87 | } 88 | 89 | @RequestMapping(value = "/novel/edit") 90 | @CrossOrigin 91 | public List getEditNovel() { 92 | return novelService.getEditNovel(); 93 | } 94 | 95 | @RequestMapping(value = "/novel/score") 96 | @CrossOrigin 97 | public List> getNovelByScore() { 98 | return novelService.getNovelByScoreL10(); 99 | } 100 | 101 | @RequestMapping(value = "/novel/{nid}", method = RequestMethod.GET) 102 | @CrossOrigin 103 | public Map getNovelById(@PathVariable Long nid) { 104 | Map novel = novelService.getNovelByNid(nid); 105 | novel.put("scoreNum", scoreService.getScoreNumByNid(nid)); 106 | novelService.addClickNum(nid); 107 | return novel; 108 | } 109 | 110 | @RequestMapping(value = "/novel/all") 111 | @CrossOrigin 112 | public Map getNovel(@RequestParam("page") int page, @RequestParam("lid") int lid, @RequestParam("state") int state, @RequestParam("active") int active) { 113 | Page pager = PageHelper.startPage(page, 20); 114 | Map map = new HashMap<>(); 115 | Map m = new HashMap<>(); 116 | m.put("lid", lid); 117 | m.put("state", state); 118 | m.put("active", active); 119 | map.put("novel", novelService.getAllNovel(m)); 120 | map.put("total", pager.getTotal()); 121 | return map; 122 | } 123 | 124 | @RequestMapping(value = "/novel/inRank") 125 | @CrossOrigin 126 | public Map getInRank(@RequestParam("page") int page, @RequestParam("tid") int tid, @RequestParam("lid") int lid) { 127 | Page pager = PageHelper.startPage(page, 20); 128 | Map map = new HashMap<>(); 129 | if (tid == 1) { 130 | map.put("novel", novelService.getClickNovelByLid(lid)); 131 | } else if (tid == 2) { 132 | map.put("novel", novelService.getRecommendNovelByLid(lid)); 133 | } else if (tid == 3) { 134 | map.put("novel", novelService.getScoreNovelByLid(lid)); 135 | } else if (tid == 4) { 136 | map.put("novel", novelService.getNewNovelByLid(lid)); 137 | } else if (tid == 5) { 138 | Map m = new HashMap<>(); 139 | m.put("lid", lid); 140 | m.put("active", 0); 141 | map.put("novel", novelService.getFinishNovelByLid(m)); 142 | } else if (tid == 6) { 143 | map.put("novel", novelService.getCollectNovelByLid(lid)); 144 | } 145 | map.put("total", pager.getTotal()); 146 | return map; 147 | } 148 | 149 | @RequestMapping(value = "/novel/rank") 150 | @CrossOrigin 151 | public Map getNovelRank(@RequestParam("lid") int lid) { 152 | Map map = new HashMap<>(); 153 | map.put("clickNovel", novelService.getClickNovelByLidL10(lid)); 154 | map.put("recommendNovel", novelService.getRecommendNovelByLidL10(lid)); 155 | map.put("popularNovel", novelService.getPopularNovelByLidL10(lid)); 156 | map.put("newNovel", novelService.getNewNovelByLidL10(lid)); 157 | map.put("finishNovel", novelService.getFinishNovelByLidL10(lid)); 158 | map.put("collectNovel", novelService.getCollectNovelByLidL10(lid)); 159 | return map; 160 | } 161 | 162 | @RequestMapping(value = "/novel/all/{lid}") 163 | @CrossOrigin 164 | public Map getAllNovelByLid(@RequestParam("page") int page, @PathVariable int lid) { 165 | Page pager = PageHelper.startPage(page, 20); 166 | Map map = new HashMap<>(); 167 | map.put("novel", novelService.getAllNovelByLid(lid)); 168 | map.put("total", pager.getTotal()); 169 | return map; 170 | } 171 | 172 | @RequestMapping(value = "/novel/finish") 173 | @CrossOrigin 174 | public Map getFinishNovel(@RequestParam("page") int page, @RequestParam("lid") int lid, @RequestParam("active") int active) { 175 | Page pager = PageHelper.startPage(page, 20); 176 | Map map = new HashMap<>(); 177 | Map m = new HashMap<>(); 178 | m.put("lid", lid); 179 | m.put("active", active); 180 | map.put("novel", novelService.getFinishNovelByLid(m)); 181 | map.put("total", pager.getTotal()); 182 | return map; 183 | } 184 | 185 | @RequestMapping(value = "/classify/{lid}", method = RequestMethod.GET) 186 | @CrossOrigin 187 | public Map getNovelByCategory(@PathVariable int lid) { 188 | Map novel = new HashMap<>(); 189 | novel.put("recommendNovel", novelService.getRecommendNovelByLidL15(lid)); 190 | novel.put("newNovel", novelService.getNewNovelByLidL23(lid)); 191 | novel.put("popularNovel", novelService.getPopularNovelByLid(lid)); 192 | return novel; 193 | } 194 | 195 | @RequestMapping(value = "/search", method = RequestMethod.GET) 196 | @CrossOrigin 197 | public ResponseEntity getNovelByName(@RequestParam("page") int page, @RequestParam("name") String name, @RequestParam("active") int active) { 198 | Page pager = PageHelper.startPage(page, 10); 199 | Map map = new HashMap<>(); 200 | Map map1 = new HashMap<>(); 201 | map1.put("key", name); 202 | map1.put("active", active); 203 | map.put("novel", novelService.search(map1)); 204 | map.put("total", pager.getTotal()); 205 | return new ResponseEntity(map); 206 | } 207 | 208 | @RequestMapping(value = "/score", method = RequestMethod.POST) 209 | @CrossOrigin 210 | public ResponseEntity score(@RequestBody ScoreEntity scoreEntity) { 211 | scoreEntity.setTime(new Date().getTime()); 212 | if (scoreService.getScore(scoreEntity) != null) { 213 | scoreService.updateScore(scoreEntity); 214 | } else { 215 | scoreService.addScore(scoreEntity); 216 | } 217 | 218 | Double avg = scoreService.getAvgScoreByNid(scoreEntity.getNid()); 219 | Map map = new HashMap<>(); 220 | map.put("nid", scoreEntity.getNid()); 221 | map.put("score", avg); 222 | novelService.updateScore(map); 223 | 224 | return new ResponseEntity(null); 225 | } 226 | 227 | @RequestMapping(value = "/novelScore/{nid}/{page}") 228 | @CrossOrigin 229 | public ResponseEntity getScoreByNid(@PathVariable Long nid, @PathVariable int page) { 230 | Page pager = PageHelper.startPage(page, 15); 231 | 232 | Map map = new HashMap<>(); 233 | map.put("score", scoreService.getScoreByNid(nid)); 234 | map.put("total", pager.getTotal()); 235 | return new ResponseEntity(map); 236 | } 237 | 238 | @RequestMapping(value = "/myScore/{uid}/{nid}") 239 | @CrossOrigin 240 | public ResponseEntity getMyScore(@PathVariable int uid, @PathVariable Long nid) { 241 | ScoreEntity scoreEntity = new ScoreEntity(); 242 | scoreEntity.setNid(nid); 243 | scoreEntity.setUid(uid); 244 | return new ResponseEntity(scoreService.getScoreByUid(scoreEntity)); 245 | } 246 | 247 | @RequestMapping(value = "/score/{uid}/{page}") 248 | @CrossOrigin 249 | public ResponseEntity getScoresByUid(@PathVariable int uid, @PathVariable int page) { 250 | Page pager = PageHelper.startPage(page, 10); 251 | Map map = new HashMap<>(); 252 | map.put("score", scoreService.getScoresByUid(uid)); 253 | map.put("total", pager.getTotal()); 254 | return new ResponseEntity(map); 255 | } 256 | 257 | @RequestMapping(value = "/title/{nid}") 258 | @CrossOrigin 259 | public ResponseEntity getTitleByNid(@PathVariable("nid") Long nid) { 260 | return new ResponseEntity(novelService.getTitleByNid(nid)); 261 | } 262 | 263 | @RequestMapping(value = "/novel_exist") 264 | @CrossOrigin 265 | public ResponseEntity novelIsExist(@RequestParam("title") String title) { 266 | return new ResponseEntity(novelService.getNovelByTitle(title) != null); 267 | } 268 | 269 | @RequestMapping(value = "/novel/info/{nid}") 270 | @CrossOrigin 271 | public ResponseEntity getNovelInfo(@PathVariable("nid") Long nid) { 272 | return new ResponseEntity(novelService.getNovelByNid(nid)); 273 | } 274 | } 275 | --------------------------------------------------------------------------------