|
@@ -1,26 +1,34 @@
|
|
package com.ruoyi.system.service.impl.notice;
|
|
package com.ruoyi.system.service.impl.notice;
|
|
|
|
|
|
|
|
+import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.entity.FormalParentsStudent;
|
|
import com.ruoyi.common.core.domain.entity.FormalParentsStudent;
|
|
import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
|
|
import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.system.domain.notice.InfoPinglun;
|
|
import com.ruoyi.system.domain.notice.InfoPinglun;
|
|
import com.ruoyi.system.domain.notice.XiaoyuanInfo;
|
|
import com.ruoyi.system.domain.notice.XiaoyuanInfo;
|
|
import com.ruoyi.system.mapper.FormalParentsStudentMapper;
|
|
import com.ruoyi.system.mapper.FormalParentsStudentMapper;
|
|
import com.ruoyi.system.mapper.FormalTeacherClassMapper;
|
|
import com.ruoyi.system.mapper.FormalTeacherClassMapper;
|
|
|
|
+import com.ruoyi.system.mapper.XiaoyuanNoticeMapper;
|
|
import com.ruoyi.system.mapper.notice.XiaoyuanInfoMapper;
|
|
import com.ruoyi.system.mapper.notice.XiaoyuanInfoMapper;
|
|
import com.ruoyi.system.service.notice.IXiaoyuanInfoService;
|
|
import com.ruoyi.system.service.notice.IXiaoyuanInfoService;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import static com.ruoyi.common.constant.CacheConstants.*;
|
|
import static com.ruoyi.common.utils.PageUtils.startPage;
|
|
import static com.ruoyi.common.utils.PageUtils.startPage;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -40,6 +48,9 @@ public class XiaoyuanInfoServiceImpl implements IXiaoyuanInfoService
|
|
@Autowired
|
|
@Autowired
|
|
private FormalParentsStudentMapper formalParentsStudentMapper;
|
|
private FormalParentsStudentMapper formalParentsStudentMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询校园安全信息
|
|
* 查询校园安全信息
|
|
*
|
|
*
|
|
@@ -49,7 +60,53 @@ public class XiaoyuanInfoServiceImpl implements IXiaoyuanInfoService
|
|
@Override
|
|
@Override
|
|
public XiaoyuanInfo selectXiaoyuanInfoByInfoId(Long infoId)
|
|
public XiaoyuanInfo selectXiaoyuanInfoByInfoId(Long infoId)
|
|
{
|
|
{
|
|
- return xiaoyuanInfoMapper.selectXiaoyuanInfoByInfoId(infoId);
|
|
|
|
|
|
+ //已读数量+1
|
|
|
|
+ XiaoyuanInfo xiaoyuanInfo = xiaoyuanInfoMapper.selectXiaoyuanInfoByInfoId(infoId);
|
|
|
|
+ String infoYiDu = xiaoyuanInfo.getInfoYiDu();
|
|
|
|
+ int result = Integer.parseInt(infoYiDu) + 1;
|
|
|
|
+ xiaoyuanInfo.setInfoYiDu(String.valueOf(result));
|
|
|
|
+
|
|
|
|
+ //组装评论
|
|
|
|
+ List<InfoPinglun> infoPingLunList = xiaoyuanInfo.getInfoPingLunList();
|
|
|
|
+ if (infoPingLunList != null && infoPingLunList.size() > 0){
|
|
|
|
+ //根据评论类型进行分组评论类型 1:评论 2:回复
|
|
|
|
+ Map<String, List<InfoPinglun>> collect = infoPingLunList.stream().sorted(Comparator.comparing(InfoPinglun::getPingLunTime, Comparator.reverseOrder())).collect(Collectors.groupingBy(InfoPinglun::getInfoPingLunType));
|
|
|
|
+ if (collect != null && collect.size() > 0){
|
|
|
|
+ //所有评论类型的数据
|
|
|
|
+ List<InfoPinglun> infoPingLunListFather = collect.get("1");
|
|
|
|
+ //给他们找自己的回复类型的数据
|
|
|
|
+ if (infoPingLunListFather != null && infoPingLunListFather.size() > 0){
|
|
|
|
+ for (InfoPinglun infoPinglun : infoPingLunListFather) {
|
|
|
|
+ List<InfoPinglun> infoPinglunList = collect.get("2");
|
|
|
|
+ //回复不是空
|
|
|
|
+ if(infoPinglunList != null && infoPinglunList.size() > 0){
|
|
|
|
+ Map<Long, List<InfoPinglun>> infoPingLunListParen = infoPinglunList.stream().collect(Collectors.groupingBy(InfoPinglun::getInfoPingLunParent));
|
|
|
|
+ List<InfoPinglun> infoPinglunListCh = infoPingLunListParen.get(infoPinglun.getInfoPingLunId());
|
|
|
|
+ if (infoPinglunListCh != null && infoPinglunListCh.size() > 0){
|
|
|
|
+ infoPinglun.setInfoPingLunList(infoPinglunListCh.stream().sorted(Comparator.comparing(InfoPinglun::getPingLunTime, Comparator.reverseOrder())).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ xiaoyuanInfo.setInfoPingLunList(infoPingLunListFather);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //获取点赞/分享/这个人是否点赞信息
|
|
|
|
+ Object dianZan = redisCache.getCacheObject(XIAOYUAN_INFO_DIANZAN + xiaoyuanInfo.getInfoId());
|
|
|
|
+ if (ObjectUtils.isNotEmpty(dianZan)){
|
|
|
|
+ xiaoyuanInfo.setIsDianZan((String)dianZan);
|
|
|
|
+ }
|
|
|
|
+ Object zhuanFa = redisCache.getCacheObject(XIAOYUAN_INFO_ZHUANFA+ xiaoyuanInfo.getInfoId());
|
|
|
|
+ if (ObjectUtils.isNotEmpty(zhuanFa)){
|
|
|
|
+ xiaoyuanInfo.setInfoZhuanFa((String)zhuanFa);
|
|
|
|
+ }
|
|
|
|
+ Object dianZanUser = redisCache.getCacheObject(XIAOYUAN_INFO_DIANZAN_USER + xiaoyuanInfo.getInfoId());
|
|
|
|
+ xiaoyuanInfo.setIsDianZan("N");
|
|
|
|
+ if (ObjectUtils.isNotEmpty(dianZanUser)){
|
|
|
|
+ xiaoyuanInfo.setIsDianZan("Y");
|
|
|
|
+ }
|
|
|
|
+ xiaoyuanInfoMapper.updateXiaoyuanInfoYiDu(xiaoyuanInfo);
|
|
|
|
+ return xiaoyuanInfo;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -123,6 +180,18 @@ public class XiaoyuanInfoServiceImpl implements IXiaoyuanInfoService
|
|
return rows;
|
|
return rows;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 新增校园安全信息评论
|
|
|
|
+ * @param infoPinglun
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public int insertInfoPingLun(InfoPinglun infoPinglun) {
|
|
|
|
+ List<InfoPinglun> infoPingLunList = new ArrayList<>();
|
|
|
|
+ infoPingLunList.add(infoPinglun);
|
|
|
|
+ return xiaoyuanInfoMapper.batchInfoPingLun(infoPingLunList);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 修改校园安全信息
|
|
* 修改校园安全信息
|
|
*
|
|
*
|
|
@@ -139,6 +208,64 @@ public class XiaoyuanInfoServiceImpl implements IXiaoyuanInfoService
|
|
return xiaoyuanInfoMapper.updateXiaoyuanInfo(xiaoyuanInfo);
|
|
return xiaoyuanInfoMapper.updateXiaoyuanInfo(xiaoyuanInfo);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 点赞接口/取消点赞
|
|
|
|
+ * @param xiaoyuanInfo
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult dianZan(XiaoyuanInfo xiaoyuanInfo) {
|
|
|
|
+ //从redis中获取点赞数量
|
|
|
|
+ // key =xiaoyuan_info_dianzan:时间:xiaoyuan_info表中的info_id
|
|
|
|
+ //value = 点赞数量
|
|
|
|
+ //谁点赞了,key = xiaoyuan_info_dianzan_user:xiaoyuan_info表中的info_id
|
|
|
|
+ //value = user_id
|
|
|
|
+
|
|
|
|
+ Object cacheObject = redisCache.getCacheObject(XIAOYUAN_INFO_DIANZAN_USER + xiaoyuanInfo.getInfoId());
|
|
|
|
+ //获取点赞数量
|
|
|
|
+ Object dianZanNum = redisCache.getCacheObject(XIAOYUAN_INFO_DIANZAN + xiaoyuanInfo.getInfoId());
|
|
|
|
+ if (ObjectUtils.isEmpty(cacheObject)){
|
|
|
|
+ //如果是空,则给这个人点赞
|
|
|
|
+ redisCache.setCacheObject(XIAOYUAN_INFO_DIANZAN_USER + xiaoyuanInfo.getInfoId(),SecurityUtils.getUserId());
|
|
|
|
+ if (ObjectUtils.isEmpty(dianZanNum)){
|
|
|
|
+ redisCache.setCacheObject(XIAOYUAN_INFO_DIANZAN + xiaoyuanInfo.getInfoId(),1);
|
|
|
|
+ }else {
|
|
|
|
+ redisCache.setCacheObject(XIAOYUAN_INFO_DIANZAN + xiaoyuanInfo.getInfoId(),(int)dianZanNum + 1);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ //删除这个key
|
|
|
|
+ redisCache.deleteObject(XIAOYUAN_INFO_DIANZAN_USER + xiaoyuanInfo.getInfoId());
|
|
|
|
+ int i = (int) dianZanNum - 1;
|
|
|
|
+ if (i < 0){
|
|
|
|
+ i= 0;
|
|
|
|
+ }
|
|
|
|
+ redisCache.setCacheObject(XIAOYUAN_INFO_DIANZAN + xiaoyuanInfo.getInfoId(),i);
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转发接口
|
|
|
|
+ * @param xiaoyuanInfo
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public AjaxResult zhuanFa(XiaoyuanInfo xiaoyuanInfo) {
|
|
|
|
+ //从redis中获取转发数量
|
|
|
|
+ // key =xiaoyuan_info_zhuanfa:xiaoyuan_info表中的info_id
|
|
|
|
+ //value = 转发数量
|
|
|
|
+ Object number = redisCache.getCacheObject(XIAOYUAN_INFO_ZHUANFA + xiaoyuanInfo.getInfoId());
|
|
|
|
+ if (ObjectUtils.isEmpty(number)){
|
|
|
|
+ //如果是空,则给这个信息创建一个转发数量
|
|
|
|
+ redisCache.setCacheObject(XIAOYUAN_INFO_ZHUANFA + xiaoyuanInfo.getInfoId(),1);
|
|
|
|
+ }else {
|
|
|
|
+ //转发数量+1
|
|
|
|
+ redisCache.setCacheObject(XIAOYUAN_INFO_ZHUANFA + xiaoyuanInfo.getInfoId(),(int)number + 1);
|
|
|
|
+ }
|
|
|
|
+ return AjaxResult.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 批量删除校园安全信息
|
|
* 批量删除校园安全信息
|
|
*
|
|
*
|