Commit fb8c323c authored by 廖旭伟's avatar 廖旭伟

新闻增加点赞次数属性,小程序点赞,分享,浏览接口

parent 790d23a8
......@@ -87,3 +87,4 @@ ALTER TABLE `mortals_xhx_user` ADD COLUMN `companyAdress` varchar(512) COMMENT
INSERT INTO `mortals_xhx_task` (`name`, `taskKey`, `status`, `excuteService`, `excuteParam`, `excuteHost`, `excuteStrategy`, `excuteDate`, `excuteTime`, `remark`, `lastExcuteHost`, `lastExcuteTime`, `interimExcuteStatus`, `createTime`, `createUserId`, `createUserName`) VALUES ('员工名片日访问数初始化', 'StaffViewsByDayInit', '0', 'StaffViewsByDayInit', NULL, NULL, '1', '0', '00:00', NULL, NULL, NULL, '0', NULL, '1', '系统管理员');
ALTER TABLE `mortals_xhx_bussinesscard` ADD COLUMN `backdrop` varchar(256) COMMENT '名片背景';
ALTER TABLE `mortals_xhx_news` ADD COLUMN `upNums` tinyint(4) NOT NULL DEFAULT '0' COMMENT '点赞次数';
\ No newline at end of file
......@@ -157,4 +157,82 @@ public class NewsApiController extends AbstractBaseController<NewsReq> {
}
return rest;
}
/**
* 新闻点赞
*/
@PostMapping(value = "up")
public Rest<NewsEntity> upNews(@RequestBody NewsReq newsReq) {
String busiDesc = "新闻点赞";
log.info("【{}】【请求体】--> {}", busiDesc, JSONObject.toJSONString(newsReq));
Rest<NewsEntity> rest = Rest.ok(busiDesc + " 【成功】");
Context context = this.getContext();
Map<String, Object> model = new HashMap<>();
try {
if (ObjectUtils.isEmpty(newsReq.getId())) {
throw new AppException("新闻id不能为空!");
}
NewsEntity newsEntity = newsService.upNews(newsReq.getId());
rest.setData(newsEntity);
this.init(model, context);
rest.setDict(model.get("dict"));
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
/**
* 新闻浏览
*/
@PostMapping(value = "view")
public Rest<NewsEntity> viewNews(@RequestBody NewsReq newsReq) {
String busiDesc = "新闻浏览";
log.info("【{}】【请求体】--> {}", busiDesc, JSONObject.toJSONString(newsReq));
Rest<NewsEntity> rest = Rest.ok(busiDesc + " 【成功】");
Context context = this.getContext();
Map<String, Object> model = new HashMap<>();
try {
if (ObjectUtils.isEmpty(newsReq.getId())) {
throw new AppException("新闻id不能为空!");
}
NewsEntity newsEntity = newsService.viewNews(newsReq.getId(),context);
rest.setData(newsEntity);
this.init(model, context);
rest.setDict(model.get("dict"));
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
/**
* 新闻分享
*/
@PostMapping(value = "share")
public Rest<NewsEntity> shareNews(@RequestBody NewsReq newsReq) {
String busiDesc = "新闻分享";
log.info("【{}】【请求体】--> {}", busiDesc, JSONObject.toJSONString(newsReq));
Rest<NewsEntity> rest = Rest.ok(busiDesc + " 【成功】");
Context context = this.getContext();
Map<String, Object> model = new HashMap<>();
try {
if (ObjectUtils.isEmpty(newsReq.getId())) {
throw new AppException("新闻id不能为空!");
}
NewsEntity newsEntity = newsService.shareNews(newsReq.getId(),context);
rest.setData(newsEntity);
this.init(model, context);
rest.setDict(model.get("dict"));
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
}
......@@ -19,5 +19,8 @@ public class FeedbackVo extends BaseEntityLong {
/** 主键ID,主键,自增长列表 */
private List <Long> idList;
/**
* 头像地址
*/
private String photoPath;
}
\ No newline at end of file
package com.mortals.xhx.module.feedback.service.impl;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -7,6 +14,12 @@ import com.mortals.xhx.module.feedback.dao.FeedbackDao;
import com.mortals.xhx.module.feedback.model.FeedbackEntity;
import com.mortals.xhx.module.feedback.service.FeedbackService;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* FeedbackService
* 反馈信息 service实现
......@@ -18,4 +31,36 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class FeedbackServiceImpl extends AbstractCRUDServiceImpl<FeedbackDao, FeedbackEntity, Long> implements FeedbackService {
@Autowired
private UserService userService;
@Override
protected void saveBefore(FeedbackEntity entity, Context context) throws AppException {
super.saveBefore(entity,context);
if(StringUtils.isEmpty(entity.getTitle())){
entity.setTitle("来自微信小程序的反馈");
}
if(context!=null&&context.getUser()!=null){
UserEntity userEntity = userService.get(context.getUser().getId());
if(userEntity!=null){
entity.setFeedbackName(userEntity.getRealName());
}
}
}
@Override
protected void findAfter(FeedbackEntity params, PageInfo pageInfo, Context context, List<FeedbackEntity> list) throws AppException {
super.findAfter(params, pageInfo, context, list);
if(CollectionUtils.isNotEmpty(list)){
List<Long> userIdList = list.stream().map(FeedbackEntity::getCreateUserId).collect(Collectors.toList());
List<UserEntity> userList = userService.find(new UserQuery().idList(userIdList));
Map<Long,UserEntity> userMap = userList.parallelStream().collect(Collectors.toMap(x -> x.getId(), z -> z, (o, n) -> n));
for(FeedbackEntity item:list){
UserEntity userEntity = userMap.get(item.getCreateUserId());
if(userEntity!=null) {
item.setPhotoPath(userEntity.getPhotoPath());
}
}
}
}
}
\ No newline at end of file
......@@ -80,6 +80,10 @@ public class NewsEntity extends NewsVo {
* 备注
*/
private String remark;
/**
* 点赞次数
*/
private Integer upNums;
@Override
public int hashCode() {
return this.getId().hashCode();
......@@ -104,7 +108,7 @@ public class NewsEntity extends NewsVo {
this.content = "";
this.top = 0;
this.viewNums = 0;
this.publishTime =null;
this.publishTime = new Date();
this.editor = "";
this.shareNums = 0;
this.deptId = null;
......@@ -112,5 +116,6 @@ public class NewsEntity extends NewsVo {
this.statement = "";
this.source = "";
this.remark = "";
this.upNums = 0;
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ import com.mortals.xhx.module.news.model.NewsEntity;
* 新闻查询对象
*
* @author zxfei
* @date 2023-09-28
* @date 2024-12-04
*/
public class NewsQuery extends NewsEntity {
/** 开始 主键ID,主键,自增长 */
......@@ -138,6 +138,21 @@ public class NewsQuery extends NewsEntity {
/** 结束 更新时间 */
private String updateTimeEnd;
/** 开始 点赞次数 */
private Integer upNumsStart;
/** 结束 点赞次数 */
private Integer upNumsEnd;
/** 增加 点赞次数 */
private Integer upNumsIncrement;
/** 点赞次数列表 */
private List <Integer> upNumsList;
/** 点赞次数排除列表 */
private List <Integer> upNumsNotList;
/** 责任编辑 */
private List<String> editorList;
......@@ -911,6 +926,87 @@ public class NewsQuery extends NewsEntity {
this.updateTimeEnd = updateTimeEnd;
}
/**
* 获取 开始 点赞次数
* @return upNumsStart
*/
public Integer getUpNumsStart(){
return this.upNumsStart;
}
/**
* 设置 开始 点赞次数
* @param upNumsStart
*/
public void setUpNumsStart(Integer upNumsStart){
this.upNumsStart = upNumsStart;
}
/**
* 获取 结束 点赞次数
* @return $upNumsEnd
*/
public Integer getUpNumsEnd(){
return this.upNumsEnd;
}
/**
* 设置 结束 点赞次数
* @param upNumsEnd
*/
public void setUpNumsEnd(Integer upNumsEnd){
this.upNumsEnd = upNumsEnd;
}
/**
* 获取 增加 点赞次数
* @return upNumsIncrement
*/
public Integer getUpNumsIncrement(){
return this.upNumsIncrement;
}
/**
* 设置 增加 点赞次数
* @param upNumsIncrement
*/
public void setUpNumsIncrement(Integer upNumsIncrement){
this.upNumsIncrement = upNumsIncrement;
}
/**
* 获取 点赞次数
* @return upNumsList
*/
public List<Integer> getUpNumsList(){
return this.upNumsList;
}
/**
* 设置 点赞次数
* @param upNumsList
*/
public void setUpNumsList(List<Integer> upNumsList){
this.upNumsList = upNumsList;
}
/**
* 获取 点赞次数
* @return upNumsNotList
*/
public List<Integer> getUpNumsNotList(){
return this.upNumsNotList;
}
/**
* 设置 点赞次数
* @param upNumsNotList
*/
public void setUpNumsNotList(List<Integer> upNumsNotList){
this.upNumsNotList = upNumsNotList;
}
/**
* 获取 责任编辑
* @return editorList
......@@ -1636,6 +1732,60 @@ public class NewsQuery extends NewsEntity {
}
/**
* 设置 点赞次数
* @param upNums
*/
public NewsQuery upNums(Integer upNums){
setUpNums(upNums);
return this;
}
/**
* 设置 开始 点赞次数
* @param upNumsStart
*/
public NewsQuery upNumsStart(Integer upNumsStart){
this.upNumsStart = upNumsStart;
return this;
}
/**
* 设置 结束 点赞次数
* @param upNumsEnd
*/
public NewsQuery upNumsEnd(Integer upNumsEnd){
this.upNumsEnd = upNumsEnd;
return this;
}
/**
* 设置 增加 点赞次数
* @param upNumsIncrement
*/
public NewsQuery upNumsIncrement(Integer upNumsIncrement){
this.upNumsIncrement = upNumsIncrement;
return this;
}
/**
* 设置 点赞次数
* @param upNumsList
*/
public NewsQuery upNumsList(List<Integer> upNumsList){
this.upNumsList = upNumsList;
return this;
}
/**
* 设置 点赞次数
* @param upNumsNotList
*/
public NewsQuery upNumsNotList(List<Integer> upNumsNotList){
this.upNumsNotList = upNumsNotList;
return this;
}
/**
* 设置 责任编辑
......
package com.mortals.xhx.module.news.service;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.news.model.NewsEntity;
import com.mortals.xhx.module.news.dao.NewsDao;
......@@ -13,4 +15,29 @@ import com.mortals.xhx.module.news.dao.NewsDao;
public interface NewsService extends ICRUDService<NewsEntity,Long>{
NewsDao getDao();
/**
* 点赞
* @param id
* @return
*/
NewsEntity upNews(Long id) throws AppException;
/**
* 浏览新闻
* @param id
* @param context
* @return
* @throws AppException
*/
NewsEntity viewNews(Long id, Context context) throws AppException;
/**
* 分享新闻
* @param id
* @param context
* @return
* @throws AppException
*/
NewsEntity shareNews(Long id, Context context) throws AppException;
}
\ No newline at end of file
package com.mortals.xhx.module.news.service.impl;
import com.mortals.xhx.module.news.model.*;
import com.mortals.xhx.module.news.service.NewsRecordService;
import com.mortals.xhx.module.news.service.NewsShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.news.dao.NewsDao;
import com.mortals.xhx.module.news.model.NewsEntity;
import com.mortals.xhx.module.news.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
/**
* NewsService
* 新闻 service实现
......@@ -18,4 +24,86 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class NewsServiceImpl extends AbstractCRUDServiceImpl<NewsDao, NewsEntity, Long> implements NewsService {
@Autowired
private NewsShareService newsShareService;
@Autowired
private NewsRecordService newsRecordService;
@Override
public NewsEntity upNews(Long id) throws AppException {
NewsEntity news = this.get(id);
if(news==null){
throw new AppException("新闻不存在");
}
NewsQuery update = new NewsQuery();
update.setId(id);
update.setUpNumsIncrement(1);
return this.update(update);
}
@Override
public NewsEntity viewNews(Long id, Context context) throws AppException {
NewsEntity news = this.get(id);
if(news==null){
throw new AppException("新闻不存在");
}
if(context!=null && context.getUser()!=null) {
NewsRecordEntity newsRecordEntity = newsRecordService.selectOne(new NewsRecordQuery().newsId(id).viewId(context.getUser().getId()));
if(newsRecordEntity!=null){
NewsRecordQuery updateRecord = new NewsRecordQuery();
updateRecord.setId(newsRecordEntity.getId());
updateRecord.setSumViewsIncrement(1);
updateRecord.setViewTime(new Date());
updateRecord.setUpdateTime(new Date());
updateRecord.setUpdateUserId(context.getUser().getId());
newsRecordService.update(updateRecord);
}else {
newsRecordEntity = new NewsRecordEntity();
newsRecordEntity.initAttrValue();
newsRecordEntity.setNewsId(id);
newsRecordEntity.setViewId(context.getUser().getId());
newsRecordEntity.setViewName(context.getUser().getRealName());
newsRecordEntity.setCreateTime(new Date());
newsRecordEntity.setCreateUserId(context.getUser().getId());
newsRecordEntity.setSumViews(1);
newsRecordService.save(newsRecordEntity);
}
}
NewsQuery update = new NewsQuery();
update.setId(id);
update.setViewNumsIncrement(1);
return this.update(update);
}
@Override
public NewsEntity shareNews(Long id, Context context) throws AppException {
NewsEntity news = this.get(id);
if(news==null){
throw new AppException("新闻不存在");
}
if(context!=null && context.getUser()!=null) {
NewsShareEntity newsShareEntity = newsShareService.selectOne(new NewsShareQuery().newsId(id).createUserId(context.getUser().getId()));
if(newsShareEntity!=null){
NewsShareQuery updateShare = new NewsShareQuery();
updateShare.setId(id);
updateShare.setSumSharesIncrement(1);
updateShare.setUpdateTime(new Date());
updateShare.setUpdateUserId(context.getUser().getId());
newsShareService.update(updateShare);
}else {
newsShareEntity = new NewsShareEntity();
newsShareEntity.initAttrValue();
newsShareEntity.setNewsId(id);
newsShareEntity.setSumShares(1);
newsShareEntity.setShareName(context.getUser().getRealName());
newsShareEntity.setCreateTime(new Date());
newsShareEntity.setCreateUserId(context.getUser().getId());
newsShareService.save(newsShareEntity);
}
}
NewsQuery update = new NewsQuery();
update.setId(id);
update.setShareNumsIncrement(1);
return this.update(update);
}
}
\ No newline at end of file
package com.mortals.xhx.module.news.web;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.busiz.applets.req.NewsReq;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
......@@ -93,4 +95,54 @@ public class NewsController extends BaseCRUDJsonBodyMappingController<NewsServic
}
}
/**
* 新闻浏览
*/
@PostMapping(value = "view")
public Rest<NewsEntity> viewNews(@RequestBody NewsReq newsReq) {
String busiDesc = "新闻浏览";
Rest<NewsEntity> rest = Rest.ok(busiDesc + " 【成功】");
Context context = this.getContext();
Map<String, Object> model = new HashMap<>();
try {
if (org.springframework.util.ObjectUtils.isEmpty(newsReq.getId())) {
throw new AppException("新闻id不能为空!");
}
NewsEntity newsEntity =service.viewNews(newsReq.getId(),context);
rest.setData(newsEntity);
this.init(model, context);
rest.setDict(model.get("dict"));
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
/**
* 新闻分享
*/
@PostMapping(value = "share")
public Rest<NewsEntity> shareNews(@RequestBody NewsReq newsReq) {
String busiDesc = "新闻分享";
Rest<NewsEntity> rest = Rest.ok(busiDesc + " 【成功】");
Context context = this.getContext();
Map<String, Object> model = new HashMap<>();
try {
if (org.springframework.util.ObjectUtils.isEmpty(newsReq.getId())) {
throw new AppException("新闻id不能为空!");
}
NewsEntity newsEntity = service.shareNews(newsReq.getId(),context);
rest.setData(newsEntity);
this.init(model, context);
rest.setDict(model.get("dict"));
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
log.error(busiDesc, e);
rest = Rest.fail(super.convertException(e));
}
return rest;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment