|
@ -1,9 +1,15 @@ |
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
|
|
|
import com.epmet.commons.tools.constant.Constant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
import com.epmet.commons.tools.enums.OrgTypeEnum; |
|
|
import com.epmet.commons.tools.enums.OrgTypeEnum; |
|
|
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
@ -12,18 +18,26 @@ import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
import com.epmet.commons.tools.utils.PidUtils; |
|
|
import com.epmet.commons.tools.utils.PidUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.dao.OrganizationMessageDao; |
|
|
import com.epmet.dao.OrganizationMessageDao; |
|
|
import com.epmet.dao.OrganizationMessagePublishRangeDao; |
|
|
import com.epmet.dao.OrganizationMessagePublishRangeDao; |
|
|
|
|
|
import com.epmet.dao.UserMessageDao; |
|
|
import com.epmet.dto.OrganizationMessageFormDTO; |
|
|
import com.epmet.dto.OrganizationMessageFormDTO; |
|
|
import com.epmet.dto.OrganizationMessagePublishRangeDTO; |
|
|
import com.epmet.dto.OrganizationMessagePublishRangeDTO; |
|
|
|
|
|
import com.epmet.dto.RegisterRelationDTO; |
|
|
|
|
|
import com.epmet.dto.form.RegisterRelationPageFormDTO; |
|
|
import com.epmet.dto.result.OrganizationMessageResultDTO; |
|
|
import com.epmet.dto.result.OrganizationMessageResultDTO; |
|
|
import com.epmet.entity.OrganizationMessageEntity; |
|
|
import com.epmet.entity.OrganizationMessageEntity; |
|
|
import com.epmet.entity.OrganizationMessagePublishRangeEntity; |
|
|
import com.epmet.entity.OrganizationMessagePublishRangeEntity; |
|
|
|
|
|
import com.epmet.entity.UserMessageEntity; |
|
|
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.service.OrganizationMessageService; |
|
|
import com.epmet.service.OrganizationMessageService; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
@ -36,10 +50,16 @@ import java.util.List; |
|
|
* @author generator generator@elink-cn.com |
|
|
* @author generator generator@elink-cn.com |
|
|
* @since v1.0.0 2023-05-04 |
|
|
* @since v1.0.0 2023-05-04 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
public class OrganizationMessageServiceImpl extends BaseServiceImpl<OrganizationMessageDao, OrganizationMessageEntity> implements OrganizationMessageService { |
|
|
public class OrganizationMessageServiceImpl extends BaseServiceImpl<OrganizationMessageDao, OrganizationMessageEntity> implements OrganizationMessageService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private OrganizationMessagePublishRangeDao organizationMessagePublishRangeDao; |
|
|
private OrganizationMessagePublishRangeDao organizationMessagePublishRangeDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private UserMessageDao userMessageDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 分页列表 |
|
|
* 分页列表 |
|
@ -93,6 +113,7 @@ public class OrganizationMessageServiceImpl extends BaseServiceImpl<Organization |
|
|
messageEntity.setPublishOrgIdPath(PidUtils.convertPid2OrgIdPath(staffInfoCacheResult.getAgencyId(), staffInfoCacheResult.getAgencyPIds())); |
|
|
messageEntity.setPublishOrgIdPath(PidUtils.convertPid2OrgIdPath(staffInfoCacheResult.getAgencyId(), staffInfoCacheResult.getAgencyPIds())); |
|
|
messageEntity.setPublishOrgName(staffInfoCacheResult.getAgencyName()); |
|
|
messageEntity.setPublishOrgName(staffInfoCacheResult.getAgencyName()); |
|
|
messageEntity.setPublishTime(new Date()); |
|
|
messageEntity.setPublishTime(new Date()); |
|
|
|
|
|
messageEntity.setSendMsgRes("sending"); |
|
|
baseDao.insert(messageEntity); |
|
|
baseDao.insert(messageEntity); |
|
|
for (OrganizationMessagePublishRangeDTO dto : formDTO.getRangeList()) { |
|
|
for (OrganizationMessagePublishRangeDTO dto : formDTO.getRangeList()) { |
|
|
OrganizationMessagePublishRangeEntity rangeEntity = new OrganizationMessagePublishRangeEntity(); |
|
|
OrganizationMessagePublishRangeEntity rangeEntity = new OrganizationMessagePublishRangeEntity(); |
|
@ -105,18 +126,86 @@ public class OrganizationMessageServiceImpl extends BaseServiceImpl<Organization |
|
|
rangeEntity.setPid(gridInfoCache.getPid()); |
|
|
rangeEntity.setPid(gridInfoCache.getPid()); |
|
|
rangeEntity.setOrgIdPath(PidUtils.convertPid2OrgIdPath(dto.getOrgId(), gridInfoCache.getPids())); |
|
|
rangeEntity.setOrgIdPath(PidUtils.convertPid2OrgIdPath(dto.getOrgId(), gridInfoCache.getPids())); |
|
|
rangeEntity.setOrgName(gridInfoCache.getGridNamePath()); |
|
|
rangeEntity.setOrgName(gridInfoCache.getGridNamePath()); |
|
|
} else if (OrgTypeEnum.AGENCY.getCode().equals(dto.getOrgType())) { |
|
|
} else { |
|
|
|
|
|
//if (OrgTypeEnum.AGENCY.getCode().equals(dto.getOrgType()))
|
|
|
AgencyInfoCache agencyInfoCache = CustomerOrgRedis.getAgencyInfo(dto.getOrgId()); |
|
|
AgencyInfoCache agencyInfoCache = CustomerOrgRedis.getAgencyInfo(dto.getOrgId()); |
|
|
rangeEntity.setPid(agencyInfoCache.getPid()); |
|
|
rangeEntity.setPid(agencyInfoCache.getPid()); |
|
|
rangeEntity.setOrgIdPath(PidUtils.convertPid2OrgIdPath(dto.getOrgId(), agencyInfoCache.getPids())); |
|
|
rangeEntity.setOrgIdPath(PidUtils.convertPid2OrgIdPath(dto.getOrgId(), agencyInfoCache.getPids())); |
|
|
rangeEntity.setOrgName(agencyInfoCache.getOrganizationName()); |
|
|
rangeEntity.setOrgName(agencyInfoCache.getOrganizationName()); |
|
|
} |
|
|
} |
|
|
|
|
|
dto.setPid(rangeEntity.getPid()); |
|
|
|
|
|
dto.setOrgIdPath(rangeEntity.getOrgIdPath()); |
|
|
organizationMessagePublishRangeDao.insert(rangeEntity); |
|
|
organizationMessagePublishRangeDao.insert(rangeEntity); |
|
|
} |
|
|
} |
|
|
String messageId = messageEntity.getId(); |
|
|
String messageId = messageEntity.getId(); |
|
|
// todo 发送消息 发布范围下有哪些网格,网格下所有的注册居民,每人发送一条消息
|
|
|
// 发送消息 发布范围下有哪些网格,网格下所有的注册居民,每人发送一条消息
|
|
|
|
|
|
sendUserMsg(messageId,formDTO.getContent(),formDTO.getPublishStaffId(),formDTO.getRangeList(),messageEntity.getCustomerId()); |
|
|
return messageId; |
|
|
return messageId; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
|
|
public void sendUserMsg(String messageId, String content, String publishStaffId,List<OrganizationMessagePublishRangeDTO> rangeList, String customerId) { |
|
|
|
|
|
String result = "success"; |
|
|
|
|
|
int totalMsg = NumConstant.ZERO; |
|
|
|
|
|
try { |
|
|
|
|
|
for (OrganizationMessagePublishRangeDTO rangeDto : rangeList) { |
|
|
|
|
|
RegisterRelationPageFormDTO pageFormDTO=new RegisterRelationPageFormDTO(); |
|
|
|
|
|
pageFormDTO.setCustomerId(customerId); |
|
|
|
|
|
pageFormDTO.setFirstRegister(NumConstant.ONE_STR); |
|
|
|
|
|
pageFormDTO.setPageNo(NumConstant.ONE); |
|
|
|
|
|
pageFormDTO.setPageSize(NumConstant.TWO); |
|
|
|
|
|
// pageFormDTO.setPageSize(NumConstant.ONE_THOUSAND);
|
|
|
|
|
|
if (OrgTypeEnum.GRID.getCode().equals(rangeDto.getOrgType())) { |
|
|
|
|
|
// 查询该网格下的注册居民
|
|
|
|
|
|
pageFormDTO.setGridId(rangeDto.getOrgId()); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 查询该组织下的注册居民
|
|
|
|
|
|
pageFormDTO.setAgencyIdPath(rangeDto.getOrgIdPath()); |
|
|
|
|
|
} |
|
|
|
|
|
List<RegisterRelationDTO> list=null; |
|
|
|
|
|
do { |
|
|
|
|
|
Result<PageData<RegisterRelationDTO>> regRes = epmetUserOpenFeignClient.pageQueryRegisterUser(pageFormDTO); |
|
|
|
|
|
list = regRes.getData().getList(); |
|
|
|
|
|
for (RegisterRelationDTO regUser : list) { |
|
|
|
|
|
LambdaQueryWrapper<UserMessageEntity> queryWrapper=new LambdaQueryWrapper(); |
|
|
|
|
|
queryWrapper.eq(UserMessageEntity::getCustomerId,customerId) |
|
|
|
|
|
.eq(UserMessageEntity::getTargetId,messageId) |
|
|
|
|
|
.eq(UserMessageEntity::getUserId,regUser.getUserId()); |
|
|
|
|
|
UserMessageEntity origin=userMessageDao.selectOne(queryWrapper); |
|
|
|
|
|
if(null==origin){ |
|
|
|
|
|
UserMessageEntity userMessageEntity = new UserMessageEntity(); |
|
|
|
|
|
userMessageEntity.setCustomerId(customerId); |
|
|
|
|
|
userMessageEntity.setGridId(regUser.getGridId()); |
|
|
|
|
|
userMessageEntity.setUserId(regUser.getUserId()); |
|
|
|
|
|
userMessageEntity.setApp(AppClientConstant.APP_RESI); |
|
|
|
|
|
userMessageEntity.setTitle("您有一条社区消息!"); |
|
|
|
|
|
userMessageEntity.setMessageContent(content); |
|
|
|
|
|
userMessageEntity.setReadFlag(Constant.UNREAD); |
|
|
|
|
|
userMessageEntity.setReferer(StrConstant.EPMETY_STR); |
|
|
|
|
|
userMessageEntity.setMessageType("organization_message"); |
|
|
|
|
|
userMessageEntity.setTargetId(messageId); |
|
|
|
|
|
userMessageEntity.setCreatedBy(publishStaffId); |
|
|
|
|
|
userMessageEntity.setUpdatedBy(publishStaffId); |
|
|
|
|
|
userMessageDao.insert(userMessageEntity); |
|
|
|
|
|
totalMsg += 1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + NumConstant.ONE); |
|
|
|
|
|
} while (CollectionUtils.isNotEmpty(list) && list.size() == pageFormDTO.getPageSize()); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error(String.format("messageId:%s,发送消息异常:%s", messageId, ExceptionUtils.getErrorStackTrace(e))); |
|
|
|
|
|
result = "failed"; |
|
|
|
|
|
} finally { |
|
|
|
|
|
LambdaUpdateWrapper<OrganizationMessageEntity> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
|
|
updateWrapper.eq(OrganizationMessageEntity::getId, messageId) |
|
|
|
|
|
.set(OrganizationMessageEntity::getSendMsgRes, result) |
|
|
|
|
|
.set(OrganizationMessageEntity::getTotalReceiver, totalMsg) |
|
|
|
|
|
.set(OrganizationMessageEntity::getUpdatedTime,new Date()); |
|
|
|
|
|
baseDao.update(null, updateWrapper); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |