|
@@ -1,41 +1,37 @@
|
|
|
package org.dromara.system.service.impl.notice;
|
|
|
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Constants;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.google.api.client.util.SecurityUtils;
|
|
|
-import org.dromara.common.core.constant.UserConstants;
|
|
|
-import org.dromara.common.core.domain.model.LoginUser;
|
|
|
+
|
|
|
+import org.dromara.common.core.utils.DateUtils;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
-import org.dromara.common.core.utils.StreamUtils;
|
|
|
+
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.system.domain.FormalParentsStudent;
|
|
|
import org.dromara.system.domain.FormalTeacherClass;
|
|
|
-import org.dromara.system.domain.SysDept;
|
|
|
-import org.dromara.system.domain.SysUser;
|
|
|
-import org.dromara.system.domain.bo.SysUserBo;
|
|
|
import org.dromara.system.domain.notice.XiaoyuanNotice;
|
|
|
import org.dromara.system.domain.notice.bo.XiaoyuanNoticeBo;
|
|
|
import org.dromara.system.domain.notice.vo.XiaoyuanNoticeVo;
|
|
|
+import org.dromara.system.domain.vo.SysUserVo;
|
|
|
import org.dromara.system.mapper.FormalParentsStudentMapper;
|
|
|
import org.dromara.system.mapper.FormalTeacherClassMapper;
|
|
|
+import org.dromara.system.mapper.SysUserMapper;
|
|
|
import org.dromara.system.mapper.notice.XiaoyuanNoticeMapper;
|
|
|
import org.dromara.system.service.notice.IXiaoyuanNoticeService;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 校园新闻Service业务层处理
|
|
@@ -48,11 +44,13 @@ import java.util.Collection;
|
|
|
public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
|
|
|
private final XiaoyuanNoticeMapper baseMapper;
|
|
|
- @Autowired
|
|
|
- private FormalTeacherClassMapper formalTeacherClassMapper;
|
|
|
|
|
|
- @Autowired
|
|
|
- private FormalParentsStudentMapper formalParentsStudentMapper;
|
|
|
+ private final FormalTeacherClassMapper formalTeacherClassMapper;
|
|
|
+
|
|
|
+
|
|
|
+ private final FormalParentsStudentMapper formalParentsStudentMapper;
|
|
|
+
|
|
|
+ private final SysUserMapper sysUserMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询校园新闻
|
|
@@ -152,7 +150,6 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getSenderName()), XiaoyuanNotice::getSenderName, bo.getSenderName());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getSenderDept()), XiaoyuanNotice::getSenderDept, bo.getSenderDept());
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getSchoolName()), XiaoyuanNotice::getSchoolName, bo.getSchoolName());
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getAvatar()), XiaoyuanNotice::getAvatar, bo.getAvatar());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getComment()), XiaoyuanNotice::getComment, bo.getComment());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getPrised()), XiaoyuanNotice::getPrised, bo.getPrised());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getCollect()), XiaoyuanNotice::getCollect, bo.getCollect());
|
|
@@ -166,6 +163,10 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
public Boolean insertByBo(XiaoyuanNoticeBo bo) {
|
|
|
XiaoyuanNotice add = MapstructUtils.convert(bo, XiaoyuanNotice.class);
|
|
|
validEntityBeforeSave(add);
|
|
|
+ add.setSenderId(String.valueOf(LoginHelper.getUserId()));
|
|
|
+ add.setSenderName(LoginHelper.getLoginUser().getNickname());
|
|
|
+ SysUserVo sysUserVo = sysUserMapper.selectUserById(LoginHelper.getUserId());
|
|
|
+ add.setAvatar(sysUserVo.getAvatar());
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setNoticeId(add.getNoticeId());
|
|
@@ -177,9 +178,107 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
* 修改校园新闻
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean updateByBo(XiaoyuanNoticeBo bo) {
|
|
|
- XiaoyuanNotice update = MapstructUtils.convert(bo, XiaoyuanNotice.class);
|
|
|
- validEntityBeforeSave(update);
|
|
|
+ public Boolean updateByBo(XiaoyuanNoticeBo xiaoyuanNotice) {
|
|
|
+
|
|
|
+ //修改之前去查询
|
|
|
+ XiaoyuanNoticeVo xiaoyuanNoticeUpdate = baseMapper.selectVoById(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 ("2".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 ("3".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());
|
|
|
+ XiaoyuanNotice update = MapstructUtils.convert(xiaoyuanNotice, XiaoyuanNotice.class);
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
}
|
|
|
|
|
@@ -218,7 +317,7 @@ public class XiaoyuanNoticeServiceImpl implements IXiaoyuanNoticeService {
|
|
|
|
|
|
QueryWrapper<XiaoyuanNoticeBo> wrapper = Wrappers.query();
|
|
|
wrapper
|
|
|
- .like(StringUtils.isNotBlank(bo.getCollect()), "concat", bo.getCollect());
|
|
|
+ .like(StringUtils.isNotBlank(bo.getCollect()), "collect", bo.getCollect());
|
|
|
return wrapper;
|
|
|
}
|
|
|
}
|