Administrator 2 жил өмнө
parent
commit
4c7b97e78e

+ 7 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -93,6 +93,13 @@ public class Constants
      * 用户名称
      */
     public static final String JWT_USERNAME = Claims.SUBJECT;
+    /**
+     * 自定义常量
+     */
+    public static final String ONE = "1";
+    public static final String TWO = "2";
+    public static final String THR = "3";
+    public static final String FOR = "4";
 
     /**
      * 用户头像

+ 70 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/XiaoyuanNotice.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.domain;
 
+import com.alibaba.fastjson2.JSONObject;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
@@ -41,6 +42,10 @@ public class XiaoyuanNotice extends BaseEntity
     /** 隐私种类 0:全部 1:本班 2:仅自己 */
     @Excel(name = "隐私种类 0:全部 1:本班 2:仅自己")
     private String type;
+    //可见班级id
+    private String classIdKeJian;
+    //不可见班级id
+    private String classIdBuKeJian;
 
     /** 发件人id */
     @Excel(name = "发件人id")
@@ -61,6 +66,71 @@ public class XiaoyuanNotice extends BaseEntity
      * 头像地址
      */
     private String avatar;
+    //点赞
+    private String prised;
+    //评论
+    private String comment;
+    //收藏
+    private String collect;
+    //判断更新的类型 1:评论 2:点赞 3:收藏
+    private String updateType;
+    private String deleteId;
+
+    public String getClassIdKeJian() {
+        return classIdKeJian;
+    }
+
+    public void setClassIdKeJian(String classIdKeJian) {
+        this.classIdKeJian = classIdKeJian;
+    }
+
+    public String getClassIdBuKeJian() {
+        return classIdBuKeJian;
+    }
+
+    public void setClassIdBuKeJian(String classIdBuKeJian) {
+        this.classIdBuKeJian = classIdBuKeJian;
+    }
+
+    public String getDeleteId() {
+        return deleteId;
+    }
+
+    public void setDeleteId(String deleteId) {
+        this.deleteId = deleteId;
+    }
+
+    public String getUpdateType() {
+        return updateType;
+    }
+
+    public void setUpdateType(String updateType) {
+        this.updateType = updateType;
+    }
+
+    public String getPrised() {
+        return prised;
+    }
+
+    public void setPrised(String prised) {
+        this.prised = prised;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+
+    public String getCollect() {
+        return collect;
+    }
+
+    public void setCollect(String collect) {
+        this.collect = collect;
+    }
 
     public String getSchoolName() {
         return schoolName;

+ 110 - 15
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/XiaoyuanNoticeServiceImpl.java

@@ -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);
+
     }
 
     /**

+ 28 - 51
ruoyi-system/src/main/resources/mapper/system/XiaoyuanNoticeMapper.xml

@@ -12,6 +12,8 @@
         <result property="noticeContent" column="notice_content"/>
         <result property="status" column="status"/>
         <result property="type" column="type"/>
+        <result property="classIdKeJian" column="class_id_kejian"/>
+        <result property="classIdBuKeJian" column="class_id_bukejian"/>
         <result property="senderId" column="sender_id"/>
         <result property="senderName" column="sender_name"/>
         <result property="senderDept" column="sender_dept"/>
@@ -22,10 +24,13 @@
         <result property="remark" column="remark"/>
         <result property="avatar" column="avatar"/>
         <result property="schoolName" column="school_name"/>
+        <result property="comment" column="comment"/>
+        <result property="prised" column="prised"/>
+        <result property="collect" column="collect"/>
     </resultMap>
 
     <sql id="selectXiaoyuanNoticeVo">
-        select notice_id, image, notice_title, notice_type, notice_content, status, type,school_name,avatar, sender_id, sender_name, sender_dept, create_by, create_time, update_by, update_time, remark from xiaoyuan_notice
+        select notice_id, image, notice_title, notice_type, notice_content, status, type,school_name,avatar, sender_id, sender_name, sender_dept, create_by, create_time, update_by, update_time, remark,collect,prised,comment from xiaoyuan_notice
     </sql>
 
     <select id="selectXiaoyuanNoticeList" parameterType="XiaoyuanNotice" resultMap="XiaoyuanNoticeResult">
@@ -41,64 +46,21 @@ SELECT
 	school_name,
 	sender_id,
 	sender_name,
+	class_id_kejian,
+	class_id_bukejian
 	sender_dept,
 	create_by,
 	create_time,
 	update_by,
 	update_time,
-	remark
+	remark,
+	comment,
+	prised,
+	collect
 FROM
 	xiaoyuan_notice
 WHERE
-	type = '0'
-	UNION
-SELECT
-	notice_id,
-	image,
-	notice_title,
-	notice_type,
-	notice_content,
-	STATUS,
-	type,
-		avatar,
-	school_name,
-	sender_id,
-	sender_name,
-	sender_dept,
-	create_by,
-	create_time,
-	update_by,
-	update_time,
-	remark
-FROM
-	xiaoyuan_notice
-WHERE
-	find_in_set( sender_dept, ${senderDept} )
-	and type = '1'
-	 UNION
-SELECT
-	notice_id,
-	image,
-	notice_title,
-	notice_type,
-	notice_content,
-	STATUS,
-	type,
-		avatar,
-	school_name,
-	sender_id,
-	sender_name,
-	sender_dept,
-	create_by,
-	create_time,
-	update_by,
-	update_time,
-	remark
-FROM
-	xiaoyuan_notice
-WHERE
-	sender_id = ${senderId}
-	AND type = '2'
+	(type = '0') or (type = '3' and sender_id = #{senderId}) or (type = '1' and find_in_set_multiple(#{senderDept},class_id_kejian)) or (type = '2' and !find_in_set_multiple(#{senderDept},class_id_bukejian)) order by create_time DESC
     </select>
 
     <select id="selectXiaoyuanNoticeByNoticeId" parameterType="Integer" resultMap="XiaoyuanNoticeResult">
@@ -119,6 +81,8 @@ WHERE
             <if test="noticeContent != null and noticeContent != ''">notice_content,</if>
             <if test="status != null and status != ''">status,</if>
             <if test="type != null and type != ''">type,</if>
+            <if test="classIdKeJian != null and classIdKeJian != ''">class_id_kejian,</if>
+            <if test="classIdBuKeJian != null and classIdBuKeJian != ''">class_id_bukejian,</if>
             <if test="schoolName != null and schoolName != ''">school_name,</if>
             <if test="avatar != null and avatar != ''">avatar,</if>
             <if test="senderId != null">sender_id,</if>
@@ -129,6 +93,9 @@ WHERE
             <if test="updateBy != null">update_by,</if>
             <if test="updateTime != null">update_time,</if>
             <if test="remark != null">remark,</if>
+            <if test="comment != null">comment,</if>
+            <if test="prised != null">prised,</if>
+            <if test="collect != null">collect,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="image != null">#{image},</if>
@@ -137,6 +104,8 @@ WHERE
             <if test="noticeContent != null and noticeContent != ''">#{noticeContent},</if>
             <if test="status != null and status != ''">#{status},</if>
             <if test="type != null and type != ''">#{type},</if>
+            <if test="classIdKeJian != null and classIdKeJian != ''">#{classIdKeJian},</if>
+            <if test="classIdBuKeJian != null and classIdBuKeJian != ''">#{classIdBuKeJian},</if>
             <if test="schoolName != null and schoolName != ''">#{schoolName},</if>
             <if test="avatar != null and avatar != ''">#{avatar},</if>
             <if test="senderId != null">#{senderId},</if>
@@ -147,6 +116,9 @@ WHERE
             <if test="updateBy != null">#{updateBy},</if>
             <if test="updateTime != null">#{updateTime},</if>
             <if test="remark != null">#{remark},</if>
+            <if test="comment != null">#{comment},</if>
+            <if test="prised != null">#{prised},</if>
+            <if test="collect != null">#{collect},</if>
         </trim>
     </insert>
 
@@ -159,6 +131,8 @@ WHERE
             <if test="noticeContent != null and noticeContent != ''">notice_content = #{noticeContent},</if>
             <if test="status != null and status != ''">status = #{status},</if>
             <if test="type != null and type != ''">type = #{type},</if>
+            <if test="classIdKeJian != null and classIdKeJian != ''">class_id_kejian = #{classIdKeJian},</if>
+            <if test="classIdBuKeJian != null and classIdBuKeJian != ''">class_id_bukejian = #{classIdBuKeJian},</if>
             <if test="schoolName != null and schoolName != ''">school_name = #{schoolName},</if>
             <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
             <if test="senderId != null">sender_id = #{senderId},</if>
@@ -169,6 +143,9 @@ WHERE
             <if test="updateBy != null">update_by = #{updateBy},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="remark != null">remark = #{remark},</if>
+            <if test="comment != null">comment = #{comment},</if>
+            <if test="prised != null">prised = #{prised},</if>
+            <if test="collect != null">collect = #{collect},</if>
         </trim>
         where notice_id = #{noticeId}
     </update>