message概览

master
lld 2026-04-02 01:31:26 +08:00
parent 2da9a54c30
commit b14c1d6c6d
10 changed files with 133 additions and 11 deletions

View File

@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -174,7 +175,8 @@ public class DeviceStatusHandler {
List<SysAgriInfo> msgList = new ArrayList<>();
// 仅当up且所有key为数字时才更新最新状态缓存
for (String key : payloadObj.keySet()) {
BigDecimal value = payloadObj.getBigDecimal(key);
BigDecimal value = payloadObj.getBigDecimal(key)
.divide(new BigDecimal(10),1, RoundingMode.HALF_UP);
String valueIndex = key.substring(2);
SysAgriInfo sysAgriInfo = new SysAgriInfo();
BeanUtils.copyProperties(agriInfo, sysAgriInfo);

View File

@ -269,10 +269,9 @@ public class FrontendControlHandler {
}
for (SysMessage message : messages) {
Map<String, Object> alarmMsg = new HashMap<>();
alarmMsg.put("msg",message.getContent());
alarmMsg.put("time", LocalDateTime.now().format(DATE_TIME_FORMATTER));
alarmMsg.put("msgType", message);
String alarmMessage = objectMapper.writeValueAsString(alarmMsg);
mqttMessageSender.publish("frontend/" + message.getImei() + "/alarm", alarmMessage);
mqttMessageSender.publish("device/" + message.getImei() + "/alarm", alarmMessage);
}
}
}

View File

@ -1,7 +1,12 @@
package com.agri.system.controller;
import java.util.List;
import java.util.Queue;
import javax.servlet.http.HttpServletResponse;
import com.agri.common.utils.SecurityUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -109,4 +114,51 @@ public class SysMessageController extends BaseController
{
return toAjax(sysMessageService.deleteSysMessageByIds(ids));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('warn:message:list')")
@GetMapping("/getNewMessage")
public AjaxResult getNewMessage(SysMessage sysMessage)
{
List<SysMessage> list = sysMessageService.selectSysMessageList(sysMessage);
return success(list);
}
@PreAuthorize("@ss.hasPermi('warn:message:edit')")
@Log(title = "系统消息中心", businessType = BusinessType.UPDATE)
@PutMapping("/updateRead")
public AjaxResult updateRead(@RequestBody SysMessage sysMessage)
{
if (SecurityUtils.isAdmin()) return success();
sysMessageService.lambdaUpdate()
.eq(SysMessage::getReceiver, SecurityUtils.getUserId())
.eq(SysMessage::getReadStatus, 0)
.eq(StringUtils.isNotBlank(sysMessage.getMsgType()),
SysMessage::getMsgType, sysMessage.getMsgType())
.set(SysMessage::getReadStatus, 1)
.update();
return success();
}
@PreAuthorize("@ss.hasPermi('warn:message:remove')")
@Log(title = "排量删除历史记录", businessType = BusinessType.DELETE)
@DeleteMapping("/removeBatch")
public AjaxResult removeBatch(@RequestBody SysMessage sysMessage)
{
QueryWrapper<SysMessage> wrapper = new QueryWrapper<>();
wrapper.eq("receiver", SecurityUtils.getUserId());
wrapper.eq("msg_type", sysMessage.getMsgType());
sysMessageService.remove(wrapper);
return success();
}
@PreAuthorize("@ss.hasPermi('warn:message:list')")
@GetMapping("/getMsgOverview")
public AjaxResult getMsgOverview(SysMessage sysMessage)
{
List<SysMessage> list = sysMessageService.getMsgOverview(sysMessage);
return success(list);
}
}

View File

@ -36,6 +36,7 @@ public class SysMessage extends BaseEntity
private String imei;
/** 接收人all=全体用户,其他=用户ID */
@Excel(name = "接收人all=全体用户,其他=用户ID")
@JsonSerialize(using = ToStringSerializer.class)
private Long receiver;
/** 消息标题 */
@ -70,5 +71,15 @@ public class SysMessage extends BaseEntity
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
private LocalDate monitorDate;
@TableField(exist = false)
private List<String> imeiList;
@TableField(exist = false)
@JsonSerialize(using = ToStringSerializer.class)
private Long sortOldId;
@TableField(exist = false)
@JsonSerialize(using = ToStringSerializer.class)
private Long sortNewId;
}

View File

@ -28,6 +28,8 @@ public interface SysMessageMapper extends BaseMapper<SysMessage>
*/
public List<SysMessage> selectSysMessageList(SysMessage sysMessage);
/**
*
*
@ -59,4 +61,11 @@ public interface SysMessageMapper extends BaseMapper<SysMessage>
* @return
*/
public int deleteSysMessageByIds(Long[] ids);
/**
*
* @param sysMessage
* @return
*/
List<SysMessage> getMsgOverview(SysMessage sysMessage);
}

View File

@ -58,4 +58,6 @@ public interface ISysMessageService extends IService<SysMessage> {
* @return
*/
public int deleteSysMessageById(Long id);
List<SysMessage> getMsgOverview(SysMessage sysMessage);
}

View File

@ -47,6 +47,9 @@ public class AgriServiceImpl implements AgriService {
List<SysMessage> msgList = new ArrayList<>();
for (SysAgriInfo agriInfo : offlineList) {
if (Objects.equals(agriInfo.getImei(), "864865085003722")) {
continue;
}
SysMessage message = new SysMessage();
message.setImei(agriInfo.getImei());
message.setTitle(agriInfo.getTitle());

View File

@ -97,4 +97,10 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
{
return baseMapper.deleteSysMessageById(id);
}
@Override
public List<SysMessage> getMsgOverview(SysMessage sysMessage) {
return baseMapper.getMsgOverview(sysMessage);
}
}

View File

@ -25,7 +25,6 @@ public class UrlEncodeUtil {
agriObj.put("imei", agriInfo.getImei());
agriObj.put("agriName", agriInfo.getAgriName());
agriObj.put("agriId", agriInfo.getId().toString());
log.info("agriInfo:{}", agriInfo);
agriObj.put("workMode", agriInfo.getWorkMode());
// 2. JSON.stringify

View File

@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectSysMessageVo">
select id, receiver, title, msg_type, read_status, content, rich_content, img_url, link_url, create_by, create_time, update_by, update_time, remark from sys_message
select id, imei, receiver, title, msg_type, read_status, content, rich_content, img_url, link_url, create_by, create_time, update_by, update_time, remark from sys_message
</sql>
<select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
@ -32,6 +32,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="receiver != null and receiver != ''"> and receiver = #{receiver}</if>
<if test="title != null and title != ''"> and title = #{title}</if>
<if test="msgType != null and msgType != ''"> and msg_type = #{msgType}</if>
<if test="msgType != null and msgType == 'status'">
and DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= CURDATE()
and DATE_FORMAT(create_time, '%Y-%m-%d') &gt;= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
</if>
<if test="sortOldId != null and sortOldId != ''">
and id &lt; #{sortOldId}
</if>
<if test="sortNewId != null and sortNewId != ''">
and id &gt; #{sortNewId}
</if>
<if test="readStatus != null "> and read_status = #{readStatus}</if>
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
<if test="imeiList != null and imeiList.size() > 0">
@ -41,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</if>
</where>
order by create_time asc
order by create_time desc
</select>
<select id="selectSysMessageById" parameterType="Long" resultMap="SysMessageResult">
@ -113,4 +123,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="getMsgOverview" parameterType="SysMessage" resultMap="SysMessageResult">
SELECT
*
FROM
(
SELECT
`imei`,
`receiver`,
`title`,
`msg_type`,
`read_status`,
`content`,
`rich_content`,
`img_url`,
`link_url`,
`create_time`, -- 必须加
`id`, -- 必须加
ROW_NUMBER() OVER (PARTITION BY msg_type ORDER BY create_time DESC, id DESC) AS rn
FROM
sys_message d
WHERE
-- 正确写法:包含今天所有时间
d.create_time &gt;= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
AND d.create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
) t
WHERE
t.rn = 1;
</select>
</mapper>