message概览
parent
2da9a54c30
commit
b14c1d6c6d
|
|
@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -174,7 +175,8 @@ public class DeviceStatusHandler {
|
||||||
List<SysAgriInfo> msgList = new ArrayList<>();
|
List<SysAgriInfo> msgList = new ArrayList<>();
|
||||||
// 仅当up且所有key为数字时,才更新最新状态缓存
|
// 仅当up且所有key为数字时,才更新最新状态缓存
|
||||||
for (String key : payloadObj.keySet()) {
|
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);
|
String valueIndex = key.substring(2);
|
||||||
SysAgriInfo sysAgriInfo = new SysAgriInfo();
|
SysAgriInfo sysAgriInfo = new SysAgriInfo();
|
||||||
BeanUtils.copyProperties(agriInfo, sysAgriInfo);
|
BeanUtils.copyProperties(agriInfo, sysAgriInfo);
|
||||||
|
|
|
||||||
|
|
@ -269,10 +269,9 @@ public class FrontendControlHandler {
|
||||||
}
|
}
|
||||||
for (SysMessage message : messages) {
|
for (SysMessage message : messages) {
|
||||||
Map<String, Object> alarmMsg = new HashMap<>();
|
Map<String, Object> alarmMsg = new HashMap<>();
|
||||||
alarmMsg.put("msg",message.getContent());
|
alarmMsg.put("msgType", message);
|
||||||
alarmMsg.put("time", LocalDateTime.now().format(DATE_TIME_FORMATTER));
|
|
||||||
String alarmMessage = objectMapper.writeValueAsString(alarmMsg);
|
String alarmMessage = objectMapper.writeValueAsString(alarmMsg);
|
||||||
mqttMessageSender.publish("frontend/" + message.getImei() + "/alarm", alarmMessage);
|
mqttMessageSender.publish("device/" + message.getImei() + "/alarm", alarmMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
package com.agri.system.controller;
|
package com.agri.system.controller;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
@ -109,4 +114,51 @@ public class SysMessageController extends BaseController
|
||||||
{
|
{
|
||||||
return toAjax(sysMessageService.deleteSysMessageByIds(ids));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ public class SysMessage extends BaseEntity
|
||||||
private String imei;
|
private String imei;
|
||||||
/** 接收人:all=全体用户,其他=用户ID */
|
/** 接收人:all=全体用户,其他=用户ID */
|
||||||
@Excel(name = "接收人:all=全体用户,其他=用户ID")
|
@Excel(name = "接收人:all=全体用户,其他=用户ID")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
private Long receiver;
|
private Long receiver;
|
||||||
|
|
||||||
/** 消息标题 */
|
/** 消息标题 */
|
||||||
|
|
@ -70,5 +71,15 @@ public class SysMessage extends BaseEntity
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
|
||||||
private LocalDate monitorDate;
|
private LocalDate monitorDate;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
private List<String> imeiList;
|
private List<String> imeiList;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long sortOldId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long sortNewId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ public interface SysMessageMapper extends BaseMapper<SysMessage>
|
||||||
*/
|
*/
|
||||||
public List<SysMessage> selectSysMessageList(SysMessage sysMessage);
|
public List<SysMessage> selectSysMessageList(SysMessage sysMessage);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增系统消息中心
|
* 新增系统消息中心
|
||||||
*
|
*
|
||||||
|
|
@ -59,4 +61,11 @@ public interface SysMessageMapper extends BaseMapper<SysMessage>
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteSysMessageByIds(Long[] ids);
|
public int deleteSysMessageByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息概览
|
||||||
|
* @param sysMessage
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<SysMessage> getMsgOverview(SysMessage sysMessage);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,4 +58,6 @@ public interface ISysMessageService extends IService<SysMessage> {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteSysMessageById(Long id);
|
public int deleteSysMessageById(Long id);
|
||||||
|
|
||||||
|
List<SysMessage> getMsgOverview(SysMessage sysMessage);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,9 @@ public class AgriServiceImpl implements AgriService {
|
||||||
|
|
||||||
List<SysMessage> msgList = new ArrayList<>();
|
List<SysMessage> msgList = new ArrayList<>();
|
||||||
for (SysAgriInfo agriInfo : offlineList) {
|
for (SysAgriInfo agriInfo : offlineList) {
|
||||||
|
if (Objects.equals(agriInfo.getImei(), "864865085003722")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
SysMessage message = new SysMessage();
|
SysMessage message = new SysMessage();
|
||||||
message.setImei(agriInfo.getImei());
|
message.setImei(agriInfo.getImei());
|
||||||
message.setTitle(agriInfo.getTitle());
|
message.setTitle(agriInfo.getTitle());
|
||||||
|
|
|
||||||
|
|
@ -97,4 +97,10 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||||
{
|
{
|
||||||
return baseMapper.deleteSysMessageById(id);
|
return baseMapper.deleteSysMessageById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysMessage> getMsgOverview(SysMessage sysMessage) {
|
||||||
|
return baseMapper.getMsgOverview(sysMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ public class UrlEncodeUtil {
|
||||||
agriObj.put("imei", agriInfo.getImei());
|
agriObj.put("imei", agriInfo.getImei());
|
||||||
agriObj.put("agriName", agriInfo.getAgriName());
|
agriObj.put("agriName", agriInfo.getAgriName());
|
||||||
agriObj.put("agriId", agriInfo.getId().toString());
|
agriObj.put("agriId", agriInfo.getId().toString());
|
||||||
log.info("agriInfo:{}", agriInfo);
|
|
||||||
agriObj.put("workMode", agriInfo.getWorkMode());
|
agriObj.put("workMode", agriInfo.getWorkMode());
|
||||||
|
|
||||||
// 2. JSON.stringify
|
// 2. JSON.stringify
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectSysMessageVo">
|
<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>
|
</sql>
|
||||||
|
|
||||||
<select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
|
<select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
|
||||||
|
|
@ -32,16 +32,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="receiver != null and receiver != ''"> and receiver = #{receiver}</if>
|
<if test="receiver != null and receiver != ''"> and receiver = #{receiver}</if>
|
||||||
<if test="title != null and title != ''"> and title = #{title}</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 != ''"> and msg_type = #{msgType}</if>
|
||||||
|
<if test="msgType != null and msgType == 'status'">
|
||||||
|
and DATE_FORMAT(create_time, '%Y-%m-%d') <= CURDATE()
|
||||||
|
and DATE_FORMAT(create_time, '%Y-%m-%d') >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
|
||||||
|
</if>
|
||||||
|
<if test="sortOldId != null and sortOldId != ''">
|
||||||
|
and id < #{sortOldId}
|
||||||
|
</if>
|
||||||
|
<if test="sortNewId != null and sortNewId != ''">
|
||||||
|
and id > #{sortNewId}
|
||||||
|
</if>
|
||||||
<if test="readStatus != null "> and read_status = #{readStatus}</if>
|
<if test="readStatus != null "> and read_status = #{readStatus}</if>
|
||||||
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
|
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
|
||||||
<if test="imeiList != null and imeiList.size() > 0">
|
<if test="imeiList != null and imeiList.size() > 0">
|
||||||
imei IN
|
imei IN
|
||||||
<foreach collection="imeiList" item="imei" open="(" separator="," close=")">
|
<foreach collection="imeiList" item="imei" open="(" separator="," close=")">
|
||||||
#{imei}
|
#{imei}
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
order by create_time asc
|
order by create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectSysMessageById" parameterType="Long" resultMap="SysMessageResult">
|
<select id="selectSysMessageById" parameterType="Long" resultMap="SysMessageResult">
|
||||||
|
|
@ -113,4 +123,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</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 >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
|
||||||
|
AND d.create_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
|
||||||
|
) t
|
||||||
|
WHERE
|
||||||
|
t.rn = 1;
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue