mirror of
https://github.com/201206030/novel.git
synced 2025-07-16 17:26:38 +00:00
小说发布更新中。。。。
This commit is contained in:
@ -3,6 +3,9 @@ package com.java2nb.books.controller;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.java2nb.books.domain.BookContentDO;
|
||||
import com.java2nb.books.domain.BookIndexDO;
|
||||
import com.java2nb.books.vo.BookIndexVO;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -22,9 +25,9 @@ import com.java2nb.common.utils.PageBean;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import com.java2nb.common.utils.R;
|
||||
|
||||
import javax.jws.WebParam;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author xiongxy
|
||||
* @email 1179705413@qq.com
|
||||
* @date 2019-11-13 09:27:04
|
||||
@ -64,7 +67,7 @@ public class BookController {
|
||||
@ApiOperation(value = "修改页面", notes = "修改页面")
|
||||
@GetMapping("/edit/{id}")
|
||||
String edit(@PathVariable("id") Long id, Model model) {
|
||||
BookDO book = bookService.get(id);
|
||||
BookDO book = bookService.get(id);
|
||||
model.addAttribute("book", book);
|
||||
return "books/book/edit";
|
||||
}
|
||||
@ -72,7 +75,7 @@ public class BookController {
|
||||
@ApiOperation(value = "查看页面", notes = "查看页面")
|
||||
@GetMapping("/detail/{id}")
|
||||
String detail(@PathVariable("id") Long id, Model model) {
|
||||
BookDO book = bookService.get(id);
|
||||
BookDO book = bookService.get(id);
|
||||
model.addAttribute("book", book);
|
||||
return "books/book/detail";
|
||||
}
|
||||
@ -83,7 +86,7 @@ public class BookController {
|
||||
@ApiOperation(value = "新增", notes = "新增")
|
||||
@ResponseBody
|
||||
@PostMapping("/save")
|
||||
public R save( BookDO book) {
|
||||
public R save(BookDO book) {
|
||||
if (bookService.save(book) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
@ -96,8 +99,8 @@ public class BookController {
|
||||
@ApiOperation(value = "修改", notes = "修改")
|
||||
@ResponseBody
|
||||
@RequestMapping("/update")
|
||||
public R update( BookDO book) {
|
||||
bookService.update(book);
|
||||
public R update(BookDO book) {
|
||||
bookService.update(book);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ -107,7 +110,7 @@ public class BookController {
|
||||
@ApiOperation(value = "删除", notes = "删除")
|
||||
@PostMapping("/remove")
|
||||
@ResponseBody
|
||||
public R remove( Long id) {
|
||||
public R remove(Long id) {
|
||||
if (bookService.remove(id) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
@ -121,8 +124,69 @@ public class BookController {
|
||||
@PostMapping("/batchRemove")
|
||||
@ResponseBody
|
||||
public R remove(@RequestParam("ids[]") Long[] ids) {
|
||||
bookService.batchRemove(ids);
|
||||
bookService.batchRemove(ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "新增章节页面", notes = "新增章节页面")
|
||||
@GetMapping("/index/add")
|
||||
String indexAdd(Long bookId, Model model) {
|
||||
model.addAttribute("bookId",bookId);
|
||||
return "books/bookIndex/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存章节
|
||||
*/
|
||||
@ApiOperation(value = "新增章节", notes = "新增章节")
|
||||
@ResponseBody
|
||||
@PostMapping("/index/save")
|
||||
public R indexSave(BookIndexDO bookIndex, BookContentDO bookContent) {
|
||||
if (bookService.saveIndexAndContent(bookIndex,bookContent) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
@GetMapping("/index")
|
||||
String BookIndex() {
|
||||
return "books/bookIndex/bookIndex";
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取章节列表", notes = "获取章节列表")
|
||||
@ResponseBody
|
||||
@GetMapping("/index/list")
|
||||
public R indexList(@RequestParam Map<String, Object> params) {
|
||||
//查询列表数据
|
||||
Query query = new Query(params);
|
||||
List<BookIndexVO> bookIndexList = bookService.indexVOList(query);
|
||||
int total = bookService.indexVOCount(query);
|
||||
PageBean pageBean = new PageBean(bookIndexList, total);
|
||||
return R.ok().put("data", pageBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "删除")
|
||||
@PostMapping("/index/remove")
|
||||
@ResponseBody
|
||||
public R indexRemove( Long id) {
|
||||
if (bookService.indexRemove(id) > 0) {
|
||||
return R.ok();
|
||||
}
|
||||
return R.error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@ApiOperation(value = "批量删除", notes = "批量删除")
|
||||
@PostMapping("/index/batchRemove")
|
||||
@ResponseBody
|
||||
public R indexRemove(@RequestParam("ids[]") Long[] ids) {
|
||||
bookService.batchIndexRemove(ids);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package com.java2nb.books.dao;
|
||||
|
||||
import com.java2nb.books.domain.BookDO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -29,4 +31,6 @@ public interface BookDao {
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
void uptUpdateTime( @Param("id") Long bookId, @Param("updateTime") Date date);
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import com.java2nb.books.domain.BookIndexDO;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.java2nb.books.vo.BookIndexVO;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -31,4 +34,10 @@ public interface BookIndexDao {
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
void insertBatch(List<BookIndexDO> newBookIndexList);
|
||||
|
||||
Integer queryMaxIndexNum(@Param("bookId") Long bookId);
|
||||
|
||||
List<BookIndexVO> listVO(Query query);
|
||||
|
||||
int countVO(Query query);
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package com.java2nb.books.service;
|
||||
|
||||
import com.java2nb.books.domain.BookContentDO;
|
||||
import com.java2nb.books.domain.BookDO;
|
||||
import com.java2nb.books.domain.BookIndexDO;
|
||||
import com.java2nb.books.vo.BookIndexVO;
|
||||
import com.java2nb.common.utils.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -27,4 +31,18 @@ public interface BookService {
|
||||
int remove(Long id);
|
||||
|
||||
int batchRemove(Long[] ids);
|
||||
|
||||
/**
|
||||
* 保存章节
|
||||
*/
|
||||
int saveIndexAndContent(BookIndexDO bookIndex, BookContentDO bookContent);
|
||||
|
||||
|
||||
List<BookIndexVO> indexVOList(Query query);
|
||||
|
||||
int indexVOCount(Query query);
|
||||
|
||||
int indexRemove(Long id);
|
||||
|
||||
int batchIndexRemove(Long[] ids);
|
||||
}
|
||||
|
@ -1,21 +1,38 @@
|
||||
package com.java2nb.books.service.impl;
|
||||
|
||||
import com.java2nb.books.dao.BookContentDao;
|
||||
import com.java2nb.books.dao.BookIndexDao;
|
||||
import com.java2nb.books.domain.BookContentDO;
|
||||
import com.java2nb.books.domain.BookIndexDO;
|
||||
import com.java2nb.books.util.StringUtil;
|
||||
import com.java2nb.books.vo.BookIndexVO;
|
||||
import com.java2nb.common.utils.Query;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.java2nb.books.dao.BookDao;
|
||||
import com.java2nb.books.domain.BookDO;
|
||||
import com.java2nb.books.service.BookService;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
public class BookServiceImpl implements BookService {
|
||||
@Autowired
|
||||
private BookDao bookDao;
|
||||
|
||||
@Autowired
|
||||
private BookIndexDao bookIndexDao;
|
||||
|
||||
@Autowired
|
||||
private BookContentDao bookContentDao;
|
||||
|
||||
|
||||
@Override
|
||||
public BookDO get(Long id){
|
||||
@ -24,6 +41,11 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
@Override
|
||||
public List<BookDO> list(Map<String, Object> map){
|
||||
String sort = (String) map.get("sort");
|
||||
if(StringUtils.isNotBlank(sort)){
|
||||
map.put("sort",StringUtil.humpToLine(sort));
|
||||
|
||||
}
|
||||
return bookDao.list(map);
|
||||
}
|
||||
|
||||
@ -34,11 +56,16 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
@Override
|
||||
public int save(BookDO book){
|
||||
book.setVisitCount(0l);
|
||||
if(book.getUpdateTime() == null){
|
||||
book.setUpdateTime(new Date());
|
||||
}
|
||||
return bookDao.save(book);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(BookDO book){
|
||||
|
||||
return bookDao.update(book);
|
||||
}
|
||||
|
||||
@ -51,5 +78,43 @@ public class BookServiceImpl implements BookService {
|
||||
public int batchRemove(Long[] ids){
|
||||
return bookDao.batchRemove(ids);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int saveIndexAndContent(BookIndexDO bookIndex, BookContentDO bookContent) {
|
||||
Integer maxBookNum = bookIndexDao.queryMaxIndexNum(bookIndex.getBookId());
|
||||
int nextIndexNum = 0;
|
||||
if(maxBookNum != null){
|
||||
nextIndexNum = maxBookNum + 1;
|
||||
}
|
||||
bookIndex.setIndexNum(nextIndexNum);
|
||||
bookContent.setBookId(bookIndex.getBookId());
|
||||
bookContent.setIndexNum(nextIndexNum);
|
||||
bookDao.uptUpdateTime(bookIndex.getBookId(),new Date());
|
||||
|
||||
bookIndexDao.save(bookIndex);
|
||||
bookContentDao.save(bookContent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BookIndexVO> indexVOList(Query query) {
|
||||
return bookIndexDao.listVO(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexVOCount(Query query) {
|
||||
return bookIndexDao.countVO(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexRemove(Long id) {
|
||||
return bookIndexDao.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchIndexRemove(Long[] ids) {
|
||||
return bookIndexDao.batchRemove(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.java2nb.books.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class StringUtil {
|
||||
private static Pattern linePattern = Pattern.compile("_(\\w)");
|
||||
|
||||
/**
|
||||
* 下划线转驼峰
|
||||
*/
|
||||
public static String lineToHump(String str) {
|
||||
str = str.toLowerCase();
|
||||
Matcher matcher = linePattern.matcher(str);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static Pattern humpPattern = Pattern.compile("[A-Z]");
|
||||
|
||||
/**
|
||||
* 驼峰转下划线
|
||||
*/
|
||||
public static String humpToLine(String str) {
|
||||
Matcher matcher = humpPattern.matcher(str);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.java2nb.books.vo;
|
||||
|
||||
import com.java2nb.books.domain.BookIndexDO;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BookIndexVO extends BookIndexDO {
|
||||
|
||||
private String bookName;
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user