master
parent
09c28ce51b
commit
b75162f3de
@ -0,0 +1,23 @@
|
|||||||
|
package com.bsd.cases.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bsd.cases.service.CaseContentLikeService;
|
||||||
|
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-like")
|
||||||
|
public class CaseContentLikeController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseContentLikeService caseContentLikeService;
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,8 @@
|
|||||||
package com.bsd.cases.service;
|
package com.bsd.cases.service;
|
||||||
|
|
||||||
|
import com.bsd.cases.util.AjaxResult;
|
||||||
|
|
||||||
public interface CaseContentLikeService<CaseContentLike> extends BaseService<CaseContentLike> {
|
public interface CaseContentLikeService<CaseContentLike> extends BaseService<CaseContentLike> {
|
||||||
|
|
||||||
|
AjaxResult addLike(Long contentId);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,74 @@
|
|||||||
package com.bsd.cases.service.impl;
|
package com.bsd.cases.service.impl;
|
||||||
|
|
||||||
|
import com.bsd.cases.constants.Constants;
|
||||||
import com.bsd.cases.mapper.CaseContentLikeMapper;
|
import com.bsd.cases.mapper.CaseContentLikeMapper;
|
||||||
|
import com.bsd.cases.mapper.CaseContentMapper;
|
||||||
|
import com.bsd.cases.mapper.CaseContentStaticalMapper;
|
||||||
|
import com.bsd.cases.model.CaseContent;
|
||||||
import com.bsd.cases.model.CaseContentLike;
|
import com.bsd.cases.model.CaseContentLike;
|
||||||
|
import com.bsd.cases.model.CaseContentStatical;
|
||||||
|
import com.bsd.cases.model.CaseUsers;
|
||||||
import com.bsd.cases.service.CaseContentLikeService;
|
import com.bsd.cases.service.CaseContentLikeService;
|
||||||
|
import com.bsd.cases.service.CaseUsersService;
|
||||||
|
import com.bsd.cases.util.AjaxResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Service("caseContentLikeService")
|
@Service("caseContentLikeService")
|
||||||
@Transactional
|
@Transactional
|
||||||
public class CaseContentLikeServiceImpl extends BaseServiceImpl<CaseContentLikeMapper, CaseContentLike> implements CaseContentLikeService<CaseContentLike> {
|
public class CaseContentLikeServiceImpl extends BaseServiceImpl<CaseContentLikeMapper, CaseContentLike>
|
||||||
|
implements CaseContentLikeService<CaseContentLike> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseContentLikeMapper caseContentLikeMapper;
|
||||||
|
@Resource
|
||||||
|
private CaseUsersService caseUsersService;
|
||||||
|
@Resource
|
||||||
|
private CaseContentMapper caseContentMapper;
|
||||||
|
@Resource
|
||||||
|
private CaseContentStaticalMapper caseContentStaticalMapper;
|
||||||
|
/**
|
||||||
|
* 新增点赞
|
||||||
|
* @param contentId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult addLike(Long contentId) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
CaseUsers caseUsers = caseUsersService.currentUser();
|
||||||
|
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 {
|
||||||
|
CaseContentLike caseContentLike = new CaseContentLike();
|
||||||
|
caseContentLike.setContentId(contentId);
|
||||||
|
caseContentLike.setCreateDateTime(new Date());
|
||||||
|
caseContentLike.setUpdateDateTime(new Date());
|
||||||
|
caseContentLike.setCreateBy(caseUsers.getId());
|
||||||
|
caseContentLike.setUpdateBy(caseUsers.getId());
|
||||||
|
caseContentLike.setState(Constants.STATE_VALID);
|
||||||
|
caseContentLikeMapper.insert(caseContentLike);
|
||||||
|
CaseContentLike findCaseContentLike = new CaseContentLike();
|
||||||
|
findCaseContentLike.setContentId(contentId);
|
||||||
|
findCaseContentLike.setState(Constants.STATE_VALID);
|
||||||
|
Integer likeNum = caseContentLikeMapper.selectCount(findCaseContentLike);
|
||||||
|
CaseContentStatical findCaseContentStatical = new CaseContentStatical();
|
||||||
|
findCaseContentStatical.setState(Constants.STATE_VALID);
|
||||||
|
findCaseContentStatical.setContentId(contentId);
|
||||||
|
CaseContentStatical caseContentStatical = caseContentStaticalMapper.selectOne(findCaseContentStatical);
|
||||||
|
caseContentStatical.setLikeNum(likeNum);
|
||||||
|
caseContentStatical.setUpdateDateTime(new Date());
|
||||||
|
caseContentStaticalMapper.updateByPrimaryKeySelective(caseContentStatical);
|
||||||
|
ajaxResult.setRetmsg("已成功点赞");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.SUCCESS);
|
||||||
|
}
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue