|
@@ -1,8 +1,11 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.domain.entity.FormalParentsStudent;
|
|
|
import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
|
|
|
import com.ruoyi.common.core.domain.entity.SysRole;
|
|
@@ -14,7 +17,9 @@ import com.ruoyi.common.utils.ServletUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.system.mapper.FormalParentsStudentMapper;
|
|
|
import com.ruoyi.system.mapper.FormalTeacherClassMapper;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.system.mapper.XiaoyuanNoticeMapper;
|
|
|
import com.ruoyi.system.domain.XiaoyuanNotice;
|
|
@@ -61,7 +66,7 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
xiaoyuanNotice.setSenderId(user.getUserId().toString());
|
|
|
List<SysRole> roles = user.getRoles();
|
|
|
- String classId = "0,";
|
|
|
+ String classId = "0";
|
|
|
for (SysRole role : roles) {
|
|
|
if ("teacher".equals(role.getRoleKey())) {
|
|
|
FormalTeacherClass formalTeacherClass = new FormalTeacherClass();
|
|
@@ -73,7 +78,7 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if ("parents".equals(role.getRoleKey())){
|
|
|
+ if ("parents".equals(role.getRoleKey())) {
|
|
|
FormalParentsStudent formalParentsStudent = new FormalParentsStudent();
|
|
|
formalParentsStudent.setParentsId(user.getUserId());
|
|
|
List<FormalParentsStudent> formalParentsStudents = formalParentsStudentMapper.selectFormalParentsStudentList(formalParentsStudent);
|
|
@@ -82,7 +87,7 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(classId)){
|
|
|
+ if (StringUtils.isNotBlank(classId)) {
|
|
|
classId = classId.substring(0, classId.length() - 1);
|
|
|
}
|
|
|
//查询出所有班级id
|
|
@@ -109,17 +114,9 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
xiaoyuanNotice.setCreateTime(DateUtils.getNowDate());
|
|
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
xiaoyuanNotice.setSenderId(String.valueOf(user.getUserId()));
|
|
|
- xiaoyuanNotice.setSenderName(user.getUserName());
|
|
|
- String senderDept = xiaoyuanNotice.getSenderDept();
|
|
|
+ xiaoyuanNotice.setSenderName(user.getNickName());
|
|
|
xiaoyuanNotice.setAvatar(user.getAvatar());
|
|
|
- int result = 0;
|
|
|
- if (StringUtils.isNotBlank(senderDept)){
|
|
|
- String[] split = senderDept.split(",");
|
|
|
- for (String deptId : split) {
|
|
|
- xiaoyuanNotice.setSenderDept(deptId);
|
|
|
- result = result + xiaoyuanNoticeMapper.insertXiaoyuanNotice(xiaoyuanNotice);
|
|
|
- }
|
|
|
- }
|
|
|
+ int result = xiaoyuanNoticeMapper.insertXiaoyuanNotice(xiaoyuanNotice);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -131,8 +128,106 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
*/
|
|
|
@Override
|
|
|
public int updateXiaoyuanNotice(XiaoyuanNotice xiaoyuanNotice) {
|
|
|
+ //修改之前去查询
|
|
|
+ XiaoyuanNotice xiaoyuanNoticeUpdate = xiaoyuanNoticeMapper.selectXiaoyuanNoticeByNoticeId(xiaoyuanNotice.getNoticeId());
|
|
|
+ List<JSONObject> map = new ArrayList<>();
|
|
|
+ //判断是评论还是点赞还是收藏
|
|
|
+ UUID uuid = UUID.randomUUID();
|
|
|
+ String deleteId = xiaoyuanNotice.getDeleteId();
|
|
|
+ if (Constants.ONE.equals(xiaoyuanNotice.getUpdateType())) {
|
|
|
+ String comment = xiaoyuanNotice.getComment();
|
|
|
+ if (StringUtils.isNotBlank(comment)) {
|
|
|
+ String updateComment = xiaoyuanNoticeUpdate.getComment();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(comment);
|
|
|
+ //没有id就是新增
|
|
|
+ if (StringUtils.isEmpty(deleteId)) {
|
|
|
+ //给新增参数增加id
|
|
|
+ jsonObject.put("id", uuid);
|
|
|
+ map.add(jsonObject);
|
|
|
+ xiaoyuanNotice.setComment(map.toString());
|
|
|
+ //如果数据库中原始数据不为空
|
|
|
+ if (StringUtils.isNotBlank(updateComment)) {
|
|
|
+ updateComment = updateComment.replace("[", "").replace("]", "");
|
|
|
+ ArrayList<Object> arr = new ArrayList<>(updateComment.length());
|
|
|
+ Collections.addAll(arr, updateComment);
|
|
|
+ arr.add(jsonObject);
|
|
|
+ xiaoyuanNotice.setComment(arr.toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //删除原始数据
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(updateComment);
|
|
|
+ jsonArray.removeIf(object -> xiaoyuanNotice.getDeleteId().equals(((JSONObject) object).get("id")));
|
|
|
+ xiaoyuanNotice.setComment("");
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ xiaoyuanNotice.setComment(jsonArray.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (Constants.TWO.equals(xiaoyuanNotice.getUpdateType())) {
|
|
|
+ String prised = xiaoyuanNotice.getPrised();
|
|
|
+ String updatePrised = xiaoyuanNoticeUpdate.getPrised();
|
|
|
+ if (StringUtils.isNotBlank(prised)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(prised);
|
|
|
+ //给新增参数增加id
|
|
|
+ //没有id就是新增
|
|
|
+ if (StringUtils.isEmpty(deleteId)) {
|
|
|
+ jsonObject.put("id", uuid);
|
|
|
+ map.add(jsonObject);
|
|
|
+ xiaoyuanNotice.setPrised(map.toString());
|
|
|
+ //如果数据库中原始数据不为空
|
|
|
+ if (StringUtils.isNotBlank(updatePrised)) {
|
|
|
+ updatePrised = updatePrised.replace("[", "").replace("]", "");
|
|
|
+ ArrayList<Object> arr = new ArrayList<>(updatePrised.length());
|
|
|
+ Collections.addAll(arr, updatePrised);
|
|
|
+ arr.add(jsonObject);
|
|
|
+ xiaoyuanNotice.setPrised(arr.toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ //删除原始数据
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(updatePrised);
|
|
|
+ jsonArray.removeIf(object -> xiaoyuanNotice.getDeleteId().equals(((JSONObject) object).get("id")));
|
|
|
+ xiaoyuanNotice.setPrised("");
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ xiaoyuanNotice.setPrised(jsonArray.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (Constants.THR.equals(xiaoyuanNotice.getUpdateType())) {
|
|
|
+ String collect = xiaoyuanNotice.getCollect();
|
|
|
+ String updateCollect = xiaoyuanNoticeUpdate.getCollect();
|
|
|
+ if (StringUtils.isNotBlank(collect)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(collect);
|
|
|
+
|
|
|
+ //给新增参数增加id
|
|
|
+ //没有id就是新增
|
|
|
+ if (StringUtils.isEmpty(deleteId)) {
|
|
|
+ jsonObject.put("id", uuid);
|
|
|
+ map.add(jsonObject);
|
|
|
+ xiaoyuanNotice.setCollect(map.toString());
|
|
|
+ //如果数据库中原始数据不为空
|
|
|
+ if (StringUtils.isNotBlank(updateCollect)) {
|
|
|
+ updateCollect = updateCollect.replace("[", "").replace("]", "");
|
|
|
+ ArrayList<Object> arr = new ArrayList<>(updateCollect.length());
|
|
|
+ Collections.addAll(arr, updateCollect);
|
|
|
+ arr.add(jsonObject);
|
|
|
+ xiaoyuanNotice.setCollect(arr.toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //删除原始数据
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(updateCollect);
|
|
|
+ jsonArray.removeIf(object -> xiaoyuanNotice.getDeleteId().equals(((JSONObject) object).get("id")));
|
|
|
+ xiaoyuanNotice.setCollect("");
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ xiaoyuanNotice.setCollect(jsonArray.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
xiaoyuanNotice.setUpdateTime(DateUtils.getNowDate());
|
|
|
return xiaoyuanNoticeMapper.updateXiaoyuanNotice(xiaoyuanNotice);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|