zyy 5 years ago
commit ccb3ff7522

@ -97,10 +97,15 @@
</dependency>
<!-- pageHelper -->
<!--<dependency>-->
<!--<groupId>com.github.pagehelper</groupId>-->
<!--<artifactId>pagehelper</artifactId>-->
<!--<version>5.1.10</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!-- log4j2 -->

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.bsd.cases.service.CaseContentCommentsService;
import com.bsd.cases.util.AjaxRequest;
import com.bsd.cases.util.AjaxResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -41,4 +42,34 @@ public class CaseContentCommentsController {
}
return ajaxResult;
}
/**
*
* @param ajaxRequest
* @param request
* @return
*/
@RequestMapping("/add-comments")
public AjaxResult addComments(@RequestBody AjaxRequest ajaxRequest, HttpServletRequest request) {
AjaxResult ajaxResult = new AjaxResult();
JSONObject data = ajaxRequest.getData();
if (null == data){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("data missing");
}else {
Long contentId = data.getLong("contentId");
String comments = data.getString("comments");
if (null == contentId){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章id不可为空");
}else {
if (StringUtils.isBlank(comments)){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章评论内容不可为空");
}
}
ajaxResult =caseContentCommentsService.addComments(contentId,comments);
}
return ajaxResult;
}
}

@ -2,6 +2,7 @@ package com.bsd.cases.service;
import com.alibaba.fastjson.JSONObject;
import com.bsd.cases.util.AjaxRequest;
import com.bsd.cases.util.AjaxResult;
import com.bsd.cases.vo.CaseSearchVo;
import java.util.List;
@ -31,4 +32,7 @@ public interface CaseCategoryService<CaseCategory> extends BaseService<CaseCateg
* @return
*/
JSONObject search(String name,Integer pageNum,Integer pageSize);
AjaxResult saveOrUpdateCategory(JSONObject jsonObject);
}

@ -12,11 +12,13 @@ import com.bsd.cases.util.AjaxResult;
import com.bsd.cases.util.PageUtils;
import com.bsd.cases.vo.CaseCategoryVo;
import com.bsd.cases.vo.CaseSearchVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service("caseCategoryService")
@ -106,5 +108,62 @@ public class CaseCategoryServiceImpl extends BaseServiceImpl<CaseCategoryMapper,
return data;
}
/**
*
* @param jsonObject
* @return
*/
@Override
public AjaxResult saveOrUpdateCategory(JSONObject jsonObject) {
AjaxResult ajaxResult = new AjaxResult();
Long categoryId = jsonObject.getLong("categoryId");
String name = jsonObject.getString("name");
Integer level = jsonObject.getInteger("level");
Long parentId = jsonObject.getLong("parentId");
String url = jsonObject.getString("url");
if (null == categoryId){
//走新增
CaseCategory caseCategory = new CaseCategory();
caseCategory.setCreateDateTime(new Date());
caseCategory.setUpdateDateTime(new Date());
caseCategory.setState(Constants.STATE_VALID);
if (StringUtils.isBlank(name)){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("分类名不可为空");
return ajaxResult;
}
caseCategory.setName(name);
if (null == level){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("分级等级不可为空");
return ajaxResult;
}else {
caseCategory.setLevel(level);
if (1 != level){
if (null == parentId){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("parentId不可为空");
return ajaxResult;
}
caseCategory.setParentId(parentId);
if (3 == level){
if (StringUtils.isBlank(url)){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("三级预览图地址不可为空");
return ajaxResult;
}
caseCategory.setUrl(url);
}
}
}
}else {
//走更新
CaseCategory caseCategory = caseCategoryMapper.selectByPrimaryKey(categoryId);
}
return null;
}
}

@ -56,6 +56,7 @@ public class CaseContentCommentsServiceImpl extends BaseServiceImpl<CaseContentC
*/
@Override
public AjaxResult addComments(Long contentId,String comments) {
AjaxResult ajaxResult = new AjaxResult();
CaseUsers caseUsers = caseUsersService.currentUser();
CaseContentComments caseContentComments = new CaseContentComments();
caseContentComments.setContentId(contentId);
@ -67,7 +68,12 @@ public class CaseContentCommentsServiceImpl extends BaseServiceImpl<CaseContentC
caseContentComments.setUserName(caseUsers.getUserName());
caseContentComments.setCreateBy(caseUsers.getId());
caseContentComments.setUpdateBy(caseUsers.getId());
caseContentCommentsMapper.insert(caseContentComments);
int a = caseContentCommentsMapper.insert(caseContentComments);
if (a == 0){
ajaxResult.setRetmsg("评论失败");
ajaxResult.setRetcode(AjaxResult.FAILED);
return ajaxResult;
}
//更新统计
CaseContentStatical findCaseContentStatical = new CaseContentStatical();
findCaseContentStatical.setState(Constants.STATE_VALID);
@ -81,7 +87,8 @@ public class CaseContentCommentsServiceImpl extends BaseServiceImpl<CaseContentC
caseContentStatical.setCommentsNum(num);
caseContentStatical.setUpdateDateTime(new Date());
caseContentStaticalMapper.updateByPrimaryKeySelective(caseContentStatical);
return null;
ajaxResult.setRetmsg("评论成功");
ajaxResult.setRetcode(AjaxResult.SUCCESS);
return ajaxResult;
}
}

@ -7,7 +7,10 @@ import java.util.List;
public class PageUtils {
public static JSONObject page(List<?> list, Integer pageNum, Integer pageSize){
int page = pageNum;//相当于pageNo
int page = 1;//相当于pageNo
if (pageNum >= 1){
page = pageNum;
}
int count = pageSize;//相当于pageSize
int size = list.size();
int pageCount=size/count;

Loading…
Cancel
Save