master
ck 5 years ago
parent f941271019
commit 370caf60a4

@ -0,0 +1,47 @@
package com.bsd.cases.controller;
import com.alibaba.fastjson.JSONObject;
import com.bsd.cases.service.CaseContentScoreService;
import com.bsd.cases.util.AjaxRequest;
import com.bsd.cases.util.AjaxResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@CrossOrigin
@RestController
@RequestMapping("/case-content-score")
public class CaseContentScoreController {
@Resource
private CaseContentScoreService caseContentScoreService;
@RequestMapping("/add-score")
public AjaxResult addScore(@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");
Double score = data.getDouble("score");
if (null==contentId){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章id不可为空");
return ajaxResult;
}
if (null == score){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("评分不可为空");
return ajaxResult;
}
ajaxResult = caseContentScoreService.addScore(contentId,score);
}
return ajaxResult;
}
}

@ -0,0 +1,11 @@
package com.bsd.cases.mapper;
import com.bsd.cases.model.CaseContentScore;
import com.bsd.cases.util.CommonMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface CaseContentScoreMapper extends CommonMapper<CaseContentScore> {
Double getAverageScore(@Param("contentId")Long contentId);
}

@ -0,0 +1,16 @@
package com.bsd.cases.model;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("case_content_score")
public class CaseContentScore extends BaseEntity{
private Long contentId;
private Double score;
}

@ -0,0 +1,8 @@
package com.bsd.cases.service;
import com.bsd.cases.util.AjaxResult;
public interface CaseContentScoreService<CaseContentScore> extends BaseService<CaseContentScore> {
AjaxResult addScore(Long contentId, Double score);
}

@ -46,6 +46,13 @@ public class CaseCategoryServiceImpl extends BaseServiceImpl<CaseCategoryMapper,
return jsonObject; return jsonObject;
} }
/**
* id
* @param parentId
* @param pageNum
* @param pageSize
* @return
*/
@Override @Override
public JSONObject getCaseCategoryByParentId(Long parentId,Integer pageNum,Integer pageSize) { public JSONObject getCaseCategoryByParentId(Long parentId,Integer pageNum,Integer pageSize) {
CaseCategory findCaseCategory = new CaseCategory(); CaseCategory findCaseCategory = new CaseCategory();

@ -23,6 +23,13 @@ public class CaseContentCommentsServiceImpl extends BaseServiceImpl<CaseContentC
private CaseContentCommentsMapper caseContentCommentsMapper; private CaseContentCommentsMapper caseContentCommentsMapper;
/**
* id
* @param contentId
* @param pageNum
* @param pageSize
* @return
*/
@Override @Override
public JSONObject getCaseContentCommentsByContentId(Long contentId, Integer pageNum, Integer pageSize) { public JSONObject getCaseContentCommentsByContentId(Long contentId, Integer pageNum, Integer pageSize) {
CaseContentComments findCaseContentComments = new CaseContentComments(); CaseContentComments findCaseContentComments = new CaseContentComments();

@ -0,0 +1,73 @@
package com.bsd.cases.service.impl;
import com.bsd.cases.constants.Constants;
import com.bsd.cases.mapper.CaseContentMapper;
import com.bsd.cases.mapper.CaseContentScoreMapper;
import com.bsd.cases.mapper.CaseContentStaticalMapper;
import com.bsd.cases.model.CaseContent;
import com.bsd.cases.model.CaseContentScore;
import com.bsd.cases.model.CaseContentStatical;
import com.bsd.cases.service.CaseContentScoreService;
import com.bsd.cases.util.AjaxResult;
import org.apache.ibatis.annotations.Case;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
@Service("caseContentScoreService")
@Transactional
public class CaseContentScoreServiceImpl extends BaseServiceImpl<CaseContentScoreMapper, CaseContentScore>
implements CaseContentScoreService<CaseContentScore> {
@Resource
private CaseContentScoreMapper caseContentScoreMapper;
@Resource
private CaseContentMapper caseContentMapper;
@Resource
private CaseContentStaticalMapper caseContentStaticalMapper;
/**
*
* @param contentId
* @param score
*/
@Override
public AjaxResult addScore(Long contentId, Double score) {
AjaxResult ajaxResult = new AjaxResult();
CaseContent findCaseContent = new CaseContent();
findCaseContent.setState(Constants.STATE_VALID);
findCaseContent.setId(contentId);
CaseContent caseContent = caseContentMapper.selectOne(findCaseContent);
if (null == caseContent){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("未找到该文章");
}else {
if (score>5||score<0){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("评分不可大于5或小于0");
}else {
CaseContentScore caseContentScore = new CaseContentScore();
caseContentScore.setScore(score);
caseContentScore.setContentId(contentId);
caseContentScore.setCreateDateTime(new Date());
caseContentScore.setUpdateDateTime(new Date());
//set 人
caseContentScore.setState(Constants.STATE_VALID);
caseContentScoreMapper.insert(caseContentScore);
Double averageScore = caseContentScoreMapper.getAverageScore(contentId);
CaseContentStatical findCaseContentStatical = new CaseContentStatical();
findCaseContentStatical.setState(Constants.STATE_VALID);
findCaseContentStatical.setContentId(contentId);
CaseContentStatical caseContentStatical = caseContentStaticalMapper.selectOne(findCaseContentStatical);
caseContentStatical.setScore(averageScore);
caseContentStatical.setUpdateDateTime(new Date());
caseContentStaticalMapper.updateByPrimaryKeySelective(caseContentStatical);
ajaxResult.setRetmsg("已成功评分");
ajaxResult.setRetcode(AjaxResult.SUCCESS);
}
}
return ajaxResult;
}
}

@ -29,6 +29,8 @@ public class CaseContentDetailVo {
private Boolean isLike = false; private Boolean isLike = false;
private Boolean isScore = false;
private Integer commentsNum; private Integer commentsNum;
private Integer likeNum; private Integer likeNum;

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.cases.mapper.CaseContentScoreMapper">
<select id="getAverageScore" resultType="Double">
SELECT round(AVG(score),1)as score FROM `case_content_score` where content_id = #{contentId};
</select>
</mapper>
Loading…
Cancel
Save