通知公告弹窗
This commit is contained in:
parent
1240d87af3
commit
55bb72d1a1
|
|
@ -0,0 +1,33 @@
|
|||
package com.bonus.sgzb.system.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2024/7/8 11:16
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ExceptionEnum {
|
||||
|
||||
PARAM_NULL(1001, "参数为空"),
|
||||
SUCCESS(200, "操作成功"),
|
||||
SAVE_TO_DATABASE(500, "新增保存失败,请联系管理员!!!"),
|
||||
DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"),
|
||||
BIND_TO_DATABASE(500, "绑定失败,请联系管理员!!!"),
|
||||
UN_BIND_TO_DATABASE(500, "解绑失败,请联系管理员!!!"),
|
||||
UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!");
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.bonus.sgzb.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.sgzb.system.domain.NoticeDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
|
|
@ -67,6 +69,25 @@ public class SysNoticeController extends BaseController
|
|||
return toAjax(noticeService.insertNotice(notice));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增已读公告用户id
|
||||
*/
|
||||
@PostMapping("/addUserId")
|
||||
public AjaxResult addUserId(@Validated @RequestBody NoticeDto notice)
|
||||
{
|
||||
return noticeService.insertUserId(notice);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户筛选,获取当天最新公告信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getList")
|
||||
public AjaxResult getList()
|
||||
{
|
||||
return noticeService.getList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改通知公告
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2024/7/8 11:09
|
||||
*/
|
||||
@Data
|
||||
public class NoticeDto {
|
||||
|
||||
/** 公告ID */
|
||||
private List<Long> noticeId;
|
||||
|
||||
/** 已读公告用户id */
|
||||
private String userId;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.bonus.sgzb.system.mapper;
|
|||
|
||||
import java.util.List;
|
||||
import com.bonus.sgzb.system.domain.SysNotice;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 通知公告表 数据层
|
||||
|
|
@ -57,4 +58,26 @@ public interface SysNoticeMapper
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteNoticeByIds(Long[] noticeIds);
|
||||
|
||||
/**
|
||||
* 根据公告ID查询用户ID
|
||||
* @param noticeId
|
||||
* @return
|
||||
*/
|
||||
String selectUserIdByNoticeId(Long noticeId);
|
||||
|
||||
/**
|
||||
* 根据公告ID修改用户ID
|
||||
* @param noticeId
|
||||
* @param concatenated
|
||||
* @return
|
||||
*/
|
||||
int updateUserId(@Param("noticeId") Long noticeId, @Param("userId") String concatenated);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询公告内容
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<SysNotice> getList(String userId);
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.bonus.sgzb.system.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.system.domain.NoticeDto;
|
||||
import com.bonus.sgzb.system.domain.SysNotice;
|
||||
|
||||
/**
|
||||
|
|
@ -57,4 +60,18 @@ public interface ISysNoticeService
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteNoticeByIds(Long[] noticeIds);
|
||||
|
||||
/**
|
||||
* 新增已读公告用户id
|
||||
* @param notice
|
||||
* @return
|
||||
*/
|
||||
AjaxResult insertUserId(NoticeDto notice);
|
||||
|
||||
/**
|
||||
* 根据用户筛选,获取当天最新公告信息
|
||||
* @return
|
||||
*/
|
||||
AjaxResult getList();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
package com.bonus.sgzb.system.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||
import com.bonus.sgzb.system.config.ExceptionEnum;
|
||||
import com.bonus.sgzb.system.domain.NoticeDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.sgzb.system.domain.SysNotice;
|
||||
|
|
@ -13,6 +21,7 @@ import com.bonus.sgzb.system.service.ISysNoticeService;
|
|||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysNoticeServiceImpl implements ISysNoticeService
|
||||
{
|
||||
@Autowired
|
||||
|
|
@ -89,4 +98,59 @@ public class SysNoticeServiceImpl implements ISysNoticeService
|
|||
{
|
||||
return noticeMapper.deleteNoticeByIds(noticeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增已读公告用户id
|
||||
* @param notice
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult insertUserId(NoticeDto notice) {
|
||||
if (notice == null || CollectionUtils.isEmpty(notice.getNoticeId()) || notice.getUserId() == null) {
|
||||
return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
|
||||
}
|
||||
// 外部初始化 StringBuilder 用于构建拼接后的用户id字符串
|
||||
StringBuilder concatenatedBuilder = new StringBuilder();
|
||||
try {
|
||||
//根据公告id查询已读公告用户id
|
||||
List<Long> noticeIdList = notice.getNoticeId();
|
||||
// 循环处理每个公告ID
|
||||
for (Long noticeId : noticeIdList) {
|
||||
// 清空 StringBuilder,准备添加新的用户id
|
||||
concatenatedBuilder.setLength(0);
|
||||
String userIds = noticeMapper.selectUserIdByNoticeId(noticeId);
|
||||
if (StringUtils.isNotBlank(userIds)) {
|
||||
String[] split = userIds.split(",");
|
||||
for (String userId : split) {
|
||||
if (StringUtils.isNotBlank(userId)) {
|
||||
concatenatedBuilder.append(userId.trim()).append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加固定的 notice.getUserId()
|
||||
concatenatedBuilder.append(notice.getUserId());
|
||||
String concatenated = concatenatedBuilder.toString();
|
||||
// 将已读公告用户id更新到数据库
|
||||
int res = noticeMapper.updateUserId(noticeId, concatenated);
|
||||
if (res == 0) {
|
||||
log.error("更新公告ID为 " + noticeId + " 的已读用户ID失败");
|
||||
throw new RuntimeException("更新公告ID为 " + noticeId + " 的已读用户ID失败");
|
||||
}
|
||||
}
|
||||
return AjaxResult.success();
|
||||
} catch (Exception e) {
|
||||
log.error("更新已读公告用户ID时出现异常:" + e.getMessage());
|
||||
return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户筛选,获取当天最新公告信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getList() {
|
||||
String userId = SecurityUtils.getLoginUser().getSysUser().getUserId().toString();
|
||||
return AjaxResult.success(noticeMapper.getList(userId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
AND sn.create_by like concat('%', #{createBy}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectUserIdByNoticeId" resultType="java.lang.String">
|
||||
select user_id from sys_notice where notice_id = #{noticeId}
|
||||
</select>
|
||||
<select id="getList" resultType="com.bonus.sgzb.system.domain.SysNotice">
|
||||
SELECT
|
||||
notice_id,
|
||||
notice_title,
|
||||
notice_type,
|
||||
CAST( notice_content AS CHAR ) AS notice_content,
|
||||
STATUS,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
remark
|
||||
FROM
|
||||
sys_notice
|
||||
WHERE
|
||||
(
|
||||
user_id IS NULL
|
||||
OR user_id = ''
|
||||
OR FIND_IN_SET(#{userId}, user_id) = 0
|
||||
)
|
||||
</select>
|
||||
|
||||
<insert id="insertNotice" parameterType="com.bonus.sgzb.system.domain.SysNotice">
|
||||
insert into sys_notice (
|
||||
<if test="noticeTitle != null and noticeTitle != '' ">notice_title, </if>
|
||||
|
|
@ -85,7 +109,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</set>
|
||||
where notice_id = #{noticeId}
|
||||
</update>
|
||||
|
||||
<update id="updateUserId">
|
||||
update sys_notice set user_id = #{userId} where notice_id = #{noticeId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteNoticeById" parameterType="Long">
|
||||
delete from sys_notice where notice_id = #{noticeId}
|
||||
</delete>
|
||||
|
|
|
|||
Loading…
Reference in New Issue