Browse Source

通知公告优化改造

fuyuchuan 1 month ago
parent
commit
304b40c097

+ 2 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/domain/SysNotice.java

@@ -104,6 +104,7 @@ public class SysNotice {
         this.noticeContent = noticeContent;
     }
 
+    @NotBlank(message = "公告内容不能为空")
     public String getNoticeContent() {
         return noticeContent;
     }
@@ -148,6 +149,7 @@ public class SysNotice {
         this.endTime = endTime;
     }
 
+    @NotBlank(message = "通知接收部门id不能为空")
     public String getDeptId() {
         return deptId;
     }

+ 40 - 27
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysNoticeServiceImpl.java

@@ -1,111 +1,124 @@
 package com.usky.system.service.impl;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.google.gson.JsonObject;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.system.domain.SysNotice;
+import com.usky.system.domain.SysUser;
 import com.usky.system.mapper.SysNoticeMapper;
+import com.usky.system.mapper.SysUserMapper;
 import com.usky.system.service.ISysNoticeService;
 import com.usky.system.service.MceReceiveService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.sql.Wrapper;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 公告 服务层实现
- * 
+ *
  * @author ruoyi
  */
 @Service
-public class SysNoticeServiceImpl extends AbstractCrudService<SysNoticeMapper, SysNotice> implements ISysNoticeService
-{
+public class SysNoticeServiceImpl extends AbstractCrudService<SysNoticeMapper, SysNotice> implements ISysNoticeService {
     @Autowired
     private SysNoticeMapper noticeMapper;
 
     @Autowired
     private MceReceiveService mceReceiveService;
 
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
     /**
      * 查询公告信息
-     * 
+     *
      * @param noticeId 公告ID
      * @return 公告信息
      */
     @Override
-    public SysNotice selectNoticeById(Long noticeId)
-    {
+    public SysNotice selectNoticeById(Long noticeId) {
         return noticeMapper.selectNoticeById(noticeId);
     }
 
     /**
      * 查询公告列表
-     * 
+     *
      * @param notice 公告信息
      * @return 公告集合
      */
     @Override
-    public List<SysNotice> selectNoticeList(SysNotice notice)
-    {
+    public List<SysNotice> selectNoticeList(SysNotice notice) {
         return noticeMapper.selectNoticeList(notice);
     }
 
     /**
      * 新增公告
-     * 
+     *
      * @param notice 公告信息
      * @return 结果
      */
     @Override
-    public int insertNotice(SysNotice notice)
-    {
+    public int insertNotice(SysNotice notice) {
         noticeMapper.insertNotice(notice);
         int insertId = notice.getNoticeId();
-        JsonObject jsonObject = new JsonObject();
-        jsonObject.addProperty("infoTitle", notice.getNoticeTitle());
-        jsonObject.addProperty("infoContent",notice.getNoticeContent());
-        jsonObject.addProperty("infoType",1);
-        jsonObject.addProperty("id",insertId);
-        mceReceiveService.add(jsonObject.toString());
+
+        String deptId = notice.getDeptId();
+        List<Long> deptIds = Arrays.stream(deptId.split(",")).map(Long::parseLong).collect(Collectors.toList());
+        List<Long> usersIds = sysUserMapper.selectList(Wrappers.lambdaQuery(SysUser.class).in(SysUser::getDeptId, deptIds)).stream().map(SysUser::getUserId).collect(Collectors.toList());
+
+        if (!deptIds.isEmpty()) {
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("infoTitle", notice.getNoticeTitle());
+            jsonObject.put("infoContent", notice.getNoticeContent());
+            jsonObject.put("infoType", 1);
+            jsonObject.put("id", insertId);
+            jsonObject.put("infoTypeName", "通知公告");
+            jsonObject.put("userName", notice.getCreateBy());
+            jsonObject.put("userIds", usersIds);
+            mceReceiveService.add(jsonObject.toString());
+        }
         return insertId;
     }
 
     /**
      * 修改公告
-     * 
+     *
      * @param notice 公告信息
      * @return 结果
      */
     @Override
-    public int updateNotice(SysNotice notice)
-    {
+    public int updateNotice(SysNotice notice) {
         return noticeMapper.updateNotice(notice);
     }
 
     /**
      * 删除公告对象
-     * 
+     *
      * @param noticeId 公告ID
      * @return 结果
      */
     @Override
-    public int deleteNoticeById(Long noticeId)
-    {
+    public int deleteNoticeById(Long noticeId) {
         return noticeMapper.deleteNoticeById(noticeId);
     }
 
     /**
      * 批量删除公告信息
-     * 
+     *
      * @param noticeIds 需要删除的公告ID
      * @return 结果
      */
     @Override
-    public int deleteNoticeByIds(Long[] noticeIds)
-    {
+    public int deleteNoticeByIds(Long[] noticeIds) {
         return noticeMapper.deleteNoticeByIds(noticeIds);
     }
 }

+ 10 - 3
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysNoticeMapper.xml

@@ -28,7 +28,10 @@
                create_by,
                create_time,
                update_by,
-               update_time
+               update_time,
+               file_url,
+               author,
+               dept_id
         from sys_notice
     </sql>
 
@@ -72,6 +75,7 @@
         <if test="createBy != null and createBy != ''">create_by,</if>
         <if test="fileUrl != null and fileUrl != ''">file_url,</if>
         <if test="author != null and author != ''">author,</if>
+        <if test="deptId != null and deptId != ''">dept_id,</if>
         create_time
         )values(
         <if test="noticeTitle != null and noticeTitle != ''">#{noticeTitle},</if>
@@ -81,6 +85,7 @@
         <if test="createBy != null and createBy != ''">#{createBy},</if>
         <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
         <if test="author != null and author != ''">#{author},</if>
+        <if test="deptId != null and deptId != ''">#{deptId},</if>
         sysdate()
         )
     </insert>
@@ -93,8 +98,10 @@
             <if test="noticeContent != null">notice_content = #{noticeContent},</if>
             <if test="status != null and status != ''">status = #{status},</if>
             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
-            <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
-            <if test="author != null and author != ''">#{author},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="fileUrl != null and fileUrl != ''">file_url = #{fileUrl},</if>
+            <if test="author != null and author != ''">author = #{author},</if>
+            <if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
             update_time = sysdate()
         </set>
         where notice_id = #{noticeId}