parent
52c648ec71
commit
ca50eca8af
@ -1,11 +1,67 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.book.model.DocumentEntity;
|
||||
import com.tamguo.modules.book.service.IDocumentService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value="member/document")
|
||||
public class DocumentController {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
IDocumentService iDocumentService;
|
||||
|
||||
@RequestMapping(value = "{id}" , method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result getDocument(@PathVariable String id) {
|
||||
DocumentEntity document = null;
|
||||
try {
|
||||
document = iDocumentService.selectById(id);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage() , e );
|
||||
return Result.failResult("查询失败");
|
||||
}
|
||||
return Result.successResult(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑内容
|
||||
*/
|
||||
@RequestMapping(value = "modify" , method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result modify(DocumentEntity document) {
|
||||
try {
|
||||
iDocumentService.modify(document);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage() , e );
|
||||
return Result.failResult("保存失败");
|
||||
}
|
||||
return Result.successResult("保存成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文档
|
||||
*/
|
||||
@RequestMapping(value = "create" , method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result create(DocumentEntity document) {
|
||||
try {
|
||||
iDocumentService.create(document);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage() , e );
|
||||
return Result.failResult("保存失败");
|
||||
}
|
||||
return Result.successResult(document);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.tamguo.modules.book.model.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
import com.baomidou.mybatisplus.enums.IEnum;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*/
|
||||
public enum DocumentStatusEnum implements IEnum {
|
||||
NORMAL("normal", "正常"),
|
||||
HISTORY("history", "历史版本");
|
||||
|
||||
private String value;
|
||||
private String desc;
|
||||
|
||||
DocumentStatusEnum(final String value, final String desc) {
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Serializable getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getDesc(){
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.tamguo.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.tamguo.modules.book.model.BookCategoryEntity;
|
||||
|
||||
public interface IBookCategoryService extends IService<BookCategoryEntity>{
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.tamguo.modules.book.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.tamguo.modules.book.dao.BookCategoryMapper;
|
||||
import com.tamguo.modules.book.model.BookCategoryEntity;
|
||||
import com.tamguo.modules.book.service.IBookCategoryService;
|
||||
|
||||
@Service
|
||||
public class BookCategoryServiceImpl extends ServiceImpl<BookCategoryMapper, BookCategoryEntity> implements IBookCategoryService{
|
||||
|
||||
}
|
@ -1,13 +1,63 @@
|
||||
package com.tamguo.modules.book.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.tamguo.modules.book.dao.DocumentMapper;
|
||||
import com.tamguo.modules.book.model.DocumentEntity;
|
||||
import com.tamguo.modules.book.model.enums.DocumentStatusEnum;
|
||||
import com.tamguo.modules.book.service.IDocumentService;
|
||||
|
||||
@Service
|
||||
public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, DocumentEntity> implements IDocumentService{
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public void modify(DocumentEntity document) {
|
||||
DocumentEntity entity = this.selectById(document.getId());
|
||||
if("yes".equals(document.getCover())) {
|
||||
// 覆盖修改
|
||||
entity.setContent(document.getContent());
|
||||
entity.setMarkdown(document.getMarkdown());
|
||||
entity.setStatus(DocumentStatusEnum.NORMAL);
|
||||
this.updateById(entity);
|
||||
} else {
|
||||
String content = entity.getContent();
|
||||
String markdown = entity.getMarkdown();
|
||||
|
||||
// 更新内容
|
||||
entity.setContent(document.getContent());
|
||||
entity.setMarkdown(document.getMarkdown());
|
||||
this.updateById(entity);
|
||||
|
||||
// 新增历史
|
||||
document.setId(null);
|
||||
document.setContent(content);
|
||||
document.setMarkdown(markdown);
|
||||
document.setBookId(entity.getBookId());
|
||||
document.setCreateDate(new Date());
|
||||
document.setIsOpen(entity.getIsOpen());
|
||||
document.setName(entity.getName());
|
||||
document.setOwner(entity.getOwner());
|
||||
document.setParentId(entity.getParentId());
|
||||
document.setUpdateDate(new Date());
|
||||
document.setStatus(DocumentStatusEnum.HISTORY);
|
||||
this.insert(document);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public void create(DocumentEntity document) {
|
||||
document.setStatus(DocumentStatusEnum.NORMAL);
|
||||
document.setCreateDate(new Date());
|
||||
document.setUpdateDate(new Date());
|
||||
document.setOwner("system");
|
||||
this.insert(document);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue