|
|
|
@ -1,11 +1,29 @@ |
|
|
|
package com.zdxt.enforcementnos.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.zdxt.enforcementnos.common.LawEnforcer; |
|
|
|
import com.zdxt.enforcementnos.common.PageParam; |
|
|
|
import com.zdxt.enforcementnos.common.commonenum.PlatformTypeEnums; |
|
|
|
import com.zdxt.enforcementnos.domain.NosLawEnforcementCommentMsg; |
|
|
|
import com.zdxt.enforcementnos.domain.NosLawEnforcementTaskLawEnforcerRelation; |
|
|
|
import com.zdxt.enforcementnos.domain.SysMessageViewLog; |
|
|
|
import com.zdxt.enforcementnos.domain.vo.NosLawEnforcementCommentMsgPageVO; |
|
|
|
import com.zdxt.enforcementnos.mapper.NosLawEnforcementCommentMsgMapper; |
|
|
|
import com.zdxt.enforcementnos.service.NosLawEnforcementCommentMsgService; |
|
|
|
import com.zdxt.enforcementnos.service.NosLawEnforcementTaskLawEnforcerRelationService; |
|
|
|
import com.zdxt.enforcementnos.service.SysMessageViewLogService; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import org.dromara.common.core.exception.ServiceException; |
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo; |
|
|
|
import org.dromara.common.satoken.utils.LoginHelper; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author msy |
|
|
|
* @Date: 2026/6/3 |
|
|
|
@ -14,4 +32,93 @@ import org.springframework.stereotype.Service; |
|
|
|
public class NosLawEnforcementCommentMsgServiceImpl extends ServiceImpl<NosLawEnforcementCommentMsgMapper, NosLawEnforcementCommentMsg> |
|
|
|
implements NosLawEnforcementCommentMsgService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private NosLawEnforcementTaskLawEnforcerRelationService taskLawEnforcerRelationService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private SysMessageViewLogService sysMessageViewLogService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public TableDataInfo<NosLawEnforcementCommentMsgPageVO> commentMsgPage(PageParam pageParam) { |
|
|
|
Long userId = LoginHelper.getUserId(); |
|
|
|
Page<NosLawEnforcementCommentMsgPageVO> page = new Page<>(pageParam.getPageNo(), pageParam.getPageSize()); |
|
|
|
page = this.baseMapper.queryCommentMsgPage(page, userId); |
|
|
|
|
|
|
|
List<NosLawEnforcementCommentMsgPageVO> records = page.getRecords(); |
|
|
|
if(!records.isEmpty()) { |
|
|
|
List<String> taskIdList = records.stream().map(NosLawEnforcementCommentMsgPageVO::getTaskId).toList(); |
|
|
|
// 查询执法人员
|
|
|
|
LambdaQueryWrapper<NosLawEnforcementTaskLawEnforcerRelation> relationLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
relationLambdaQueryWrapper |
|
|
|
.in(NosLawEnforcementTaskLawEnforcerRelation::getTaskId, taskIdList); |
|
|
|
List<NosLawEnforcementTaskLawEnforcerRelation> relationList = taskLawEnforcerRelationService.list(relationLambdaQueryWrapper); |
|
|
|
Map<String, List<NosLawEnforcementTaskLawEnforcerRelation>> relationMap = relationList.stream() |
|
|
|
.collect(Collectors.groupingBy(NosLawEnforcementTaskLawEnforcerRelation::getTaskId)); |
|
|
|
|
|
|
|
// 查询当前用户是否已读
|
|
|
|
LambdaQueryWrapper<SysMessageViewLog> sysMessageViewLogLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
sysMessageViewLogLambdaQueryWrapper |
|
|
|
.eq(SysMessageViewLog::getCreateBy, userId) |
|
|
|
.eq(SysMessageViewLog::getPlatformType, PlatformTypeEnums.ENFORCEMENT.getKey()) |
|
|
|
.in(SysMessageViewLog::getSourceId, taskIdList); |
|
|
|
List<SysMessageViewLog> list = sysMessageViewLogService.list(sysMessageViewLogLambdaQueryWrapper); |
|
|
|
Map<String, Boolean> readMap = list.stream() |
|
|
|
.collect(Collectors.toMap(SysMessageViewLog::getSourceId, item -> true)); |
|
|
|
|
|
|
|
for (NosLawEnforcementCommentMsgPageVO record : records) { |
|
|
|
List<NosLawEnforcementTaskLawEnforcerRelation> relations = relationMap.get(record.getTaskId()); |
|
|
|
if (relations != null) { |
|
|
|
record.setLawEnforcer(relations.stream().map(item -> { |
|
|
|
LawEnforcer user = new LawEnforcer(); |
|
|
|
user.setLawEnforcerId(item.getLawEnforcerId()); |
|
|
|
user.setLawEnforcerName(item.getLawEnforcerName()); |
|
|
|
user.setLawEnforcerPhone(item.getLawEnforcerPhone()); |
|
|
|
user.setLawEnforcerIdCard(item.getLawEnforcerIdCard()); |
|
|
|
return user; |
|
|
|
}).toList()); |
|
|
|
} |
|
|
|
Boolean read = readMap.get(record.getId()); |
|
|
|
record.setRead(read); |
|
|
|
} |
|
|
|
} |
|
|
|
return TableDataInfo.build(page); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Integer unReadCommentMsgCount() { |
|
|
|
Long userId = LoginHelper.getUserId(); |
|
|
|
if(userId == null) { |
|
|
|
throw new ServiceException("当前用户未登录"); |
|
|
|
} |
|
|
|
return this.baseMapper.unReadCommentMsgCount(userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean markRead(String msgId) { |
|
|
|
Long userId = LoginHelper.getUserId(); |
|
|
|
|
|
|
|
NosLawEnforcementCommentMsg msg = this.baseMapper.queryCommentMsgByUser(msgId, userId); |
|
|
|
if(msg == null) { |
|
|
|
throw new ServiceException("消息不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// 先查询该用户是否已读
|
|
|
|
LambdaQueryWrapper<SysMessageViewLog> sysMessageViewLogLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
sysMessageViewLogLambdaQueryWrapper |
|
|
|
.eq(SysMessageViewLog::getSourceId, msgId) |
|
|
|
.eq(SysMessageViewLog::getCreateBy, userId); |
|
|
|
long count = sysMessageViewLogService.count(sysMessageViewLogLambdaQueryWrapper); |
|
|
|
if(count > 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
// 往sys_message_view_log表里新增一条消息和用户的关联数据,代表该用户已读此消息
|
|
|
|
SysMessageViewLog sysMessageViewLog = new SysMessageViewLog(); |
|
|
|
sysMessageViewLog.setSourceId(msgId); |
|
|
|
sysMessageViewLog.setPlatformType(PlatformTypeEnums.ENFORCEMENT.getKey()); |
|
|
|
sysMessageViewLog.setSourceType(6); |
|
|
|
return sysMessageViewLogService.save(sysMessageViewLog); |
|
|
|
} |
|
|
|
} |
|
|
|
|