|
|
@ -17,25 +17,55 @@ |
|
|
|
|
|
|
|
package com.epmet.modules.notice.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.scan.param.ImgScanParamDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.ImgTaskDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.TextScanParamDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.TextTaskDTO; |
|
|
|
import com.epmet.commons.tools.scan.result.SyncScanResult; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.ScanContentUtils; |
|
|
|
import com.epmet.constant.ReadFlagConstant; |
|
|
|
import com.epmet.dto.form.LoginUserDetailsFormDTO; |
|
|
|
import com.epmet.dto.form.UserMessageFormDTO; |
|
|
|
import com.epmet.dto.result.LoginUserDetailsResultDTO; |
|
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.modules.constant.UserMessageConstant; |
|
|
|
import com.epmet.modules.group.dao.ResiGroupDao; |
|
|
|
import com.epmet.modules.group.entity.ResiGroupEntity; |
|
|
|
import com.epmet.modules.member.dao.ResiGroupMemberDao; |
|
|
|
import com.epmet.modules.notice.dao.NoticeDao; |
|
|
|
import com.epmet.modules.notice.entity.NoticeEntity; |
|
|
|
import com.epmet.modules.notice.redis.NoticeRedis; |
|
|
|
import com.epmet.modules.notice.service.NoticeService; |
|
|
|
import com.epmet.resi.group.constant.TopicConstant; |
|
|
|
import com.epmet.resi.group.dto.member.ResiGroupMemberDTO; |
|
|
|
import com.epmet.resi.group.dto.notice.NoticeDTO; |
|
|
|
import com.epmet.resi.group.dto.topic.form.AddNoticeFormDTO; |
|
|
|
import com.epmet.resi.group.dto.topic.form.FileDTO; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 小组通知表 |
|
|
@ -45,9 +75,24 @@ import java.util.Map; |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity> implements NoticeService { |
|
|
|
|
|
|
|
private final Log logger = LogFactory.getLog(getClass()); |
|
|
|
@Autowired |
|
|
|
private NoticeRedis noticeRedis; |
|
|
|
@Value("${openapi.scan.server.url}") |
|
|
|
private String scanApiUrl; |
|
|
|
@Value("${openapi.scan.method.textSyncScan}") |
|
|
|
private String textSyncScanMethod; |
|
|
|
@Value("${openapi.scan.method.imgSyncScan}") |
|
|
|
private String imgSyncScanMethod; |
|
|
|
@Autowired |
|
|
|
private ResiGroupMemberDao resiGroupMemberDao; |
|
|
|
@Autowired |
|
|
|
private ResiGroupDao resiGroupDao; |
|
|
|
@Autowired |
|
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<NoticeDTO> page(Map<String, Object> params) { |
|
|
@ -101,4 +146,131 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeDao, NoticeEntity> |
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
* @Author sun |
|
|
|
* @Description 小组通知保存 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void add(TokenDto tokenDto, AddNoticeFormDTO formDTO) { |
|
|
|
//1.查询组内成员数据
|
|
|
|
List<ResiGroupMemberDTO> memberList = resiGroupMemberDao.getMemberList(formDTO.getGroupId()); |
|
|
|
if(CollUtil.isEmpty(memberList)){ |
|
|
|
throw new RenException(String.format("保存小组通知,获取组内成员列表失败,小组Id->", formDTO.getGroupId())); |
|
|
|
} |
|
|
|
|
|
|
|
//2.校验当前操作人员是否为组长
|
|
|
|
AtomicReference<Boolean> bl = new AtomicReference<>(true); |
|
|
|
memberList.forEach(m->{ |
|
|
|
if(m.getCustomerUserId().equals(tokenDto.getUserId())&&"leader".equals(m.getGroupLeaderFlag())){ |
|
|
|
bl.set(false); |
|
|
|
} |
|
|
|
}); |
|
|
|
if(bl.get()){ |
|
|
|
throw new RenException(String.format("保存小组通知,当前操作人员不是群组长,小组Id->", formDTO.getGroupId())); |
|
|
|
} |
|
|
|
|
|
|
|
//3.文字、图片安全校验
|
|
|
|
List<String> wordList = new ArrayList<>(); |
|
|
|
wordList.add(formDTO.getTitle());wordList.add(formDTO.getContent()); |
|
|
|
List<String> imageList = formDTO.getImageList().stream().map(FileDTO::getUrl).collect(Collectors.toList()); |
|
|
|
safetyCheck(wordList, imageList); |
|
|
|
|
|
|
|
//4.保存小组通知基础数据
|
|
|
|
//4-1.获取小组信息
|
|
|
|
ResiGroupEntity groupEntity = resiGroupDao.selectById(formDTO.getGroupId()); |
|
|
|
if(null == groupEntity){ |
|
|
|
throw new RenException(String.format("保存小组通知,获取小组数据失败,小组Id->", tokenDto.getUserId())); |
|
|
|
} |
|
|
|
//4-2.获取token用户所属组织信息
|
|
|
|
LoginUserDetailsFormDTO dto = new LoginUserDetailsFormDTO(); |
|
|
|
dto.setApp(tokenDto.getApp()); |
|
|
|
dto.setClient(tokenDto.getClient()); |
|
|
|
dto.setUserId(tokenDto.getUserId()); |
|
|
|
Result<LoginUserDetailsResultDTO> result = epmetUserOpenFeignClient.getLoginUserDetails(dto); |
|
|
|
if (!result.success() || org.springframework.util.StringUtils.isEmpty(result.getData().getAgencyId())) { |
|
|
|
throw new RenException(String.format("调用user服务查询用户数据失败,userId->", tokenDto.getUserId())); |
|
|
|
} |
|
|
|
LoginUserDetailsResultDTO resultDTO = result.getData(); |
|
|
|
|
|
|
|
//4-3.保存通知数据
|
|
|
|
NoticeEntity entity = new NoticeEntity(); |
|
|
|
entity.setCustomerId(resultDTO.getCustomerId()); |
|
|
|
entity.setAgencyId(resultDTO.getAgencyId()); |
|
|
|
entity.setGridId(groupEntity.getGridId()); |
|
|
|
entity.setGroupId(formDTO.getGroupId()); |
|
|
|
entity.setTitle(formDTO.getTitle()); |
|
|
|
entity.setContent(formDTO.getContent()); |
|
|
|
entity.setIsChange("no"); |
|
|
|
entity.setChangeTime(new Date()); |
|
|
|
insert(entity); |
|
|
|
|
|
|
|
//5.组内成员推送站内信
|
|
|
|
List<UserMessageFormDTO> userMessageFormDTOS = new ArrayList<>(); |
|
|
|
memberList.forEach(m->{ |
|
|
|
if(!"".equals(m.getGroupLeaderFlag())){ |
|
|
|
UserMessageFormDTO userMessageFormDTO = new UserMessageFormDTO(); |
|
|
|
userMessageFormDTO.setCustomerId(resultDTO.getCustomerId()); |
|
|
|
userMessageFormDTO.setUserId(m.getCustomerUserId()); |
|
|
|
userMessageFormDTO.setGridId(groupEntity.getGridId()); |
|
|
|
userMessageFormDTO.setApp(AppClientConstant.APP_RESI); |
|
|
|
userMessageFormDTO.setTitle(UserMessageConstant.GROUP_TITLE); |
|
|
|
userMessageFormDTO.setReadFlag(ReadFlagConstant.UN_READ); |
|
|
|
userMessageFormDTO.setMessageContent(String.format(UserMessageConstant.GROUP_NOTICE_ADD, groupEntity.getGroupName(), formDTO.getTitle())); |
|
|
|
userMessageFormDTOS.add(userMessageFormDTO); |
|
|
|
} |
|
|
|
}); |
|
|
|
Result sendMessageRes = epmetMessageOpenFeignClient.saveUserMessageList(userMessageFormDTOS); |
|
|
|
if (!sendMessageRes.success()) { |
|
|
|
logger.warn("小组通知,给组内成员推送站内信失败。"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 文字、图片安全校验 |
|
|
|
**/ |
|
|
|
private void safetyCheck(List<String> wordList, List<String> imageList){ |
|
|
|
if (imageList.size() != NumConstant.ZERO){ |
|
|
|
wordList.forEach(word->{ |
|
|
|
//创建话题内容审核
|
|
|
|
TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); |
|
|
|
TextTaskDTO taskDTO = new TextTaskDTO(); |
|
|
|
taskDTO.setContent(word); |
|
|
|
taskDTO.setDataId(UUID.randomUUID().toString().replace("-", "")); |
|
|
|
textScanParamDTO.getTasks().add(taskDTO); |
|
|
|
Result<SyncScanResult> textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); |
|
|
|
if (!textSyncScanResult.success()) { |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
} else { |
|
|
|
if (!textSyncScanResult.getData().isAllPass()) { |
|
|
|
logger.error(String.format(TopicConstant.CREATE_TOPIC, word)); |
|
|
|
throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//创建话题图片审核
|
|
|
|
if (imageList.size() != NumConstant.ZERO){ |
|
|
|
ImgScanParamDTO imgScanParamDTO = new ImgScanParamDTO(); |
|
|
|
imageList.forEach(url -> { |
|
|
|
ImgTaskDTO task = new ImgTaskDTO(); |
|
|
|
task.setDataId(UUID.randomUUID().toString().replace("-", "")); |
|
|
|
task.setUrl(url); |
|
|
|
imgScanParamDTO.getTasks().add(task); |
|
|
|
}); |
|
|
|
Result<SyncScanResult> imgScanResult = ScanContentUtils.imgSyncScan(scanApiUrl.concat(imgSyncScanMethod), imgScanParamDTO); |
|
|
|
if (!imgScanResult.success()){ |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
} else { |
|
|
|
if (!imgScanResult.getData().isAllPass()) { |
|
|
|
throw new RenException(EpmetErrorCode.IMG_SCAN_FAILED.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |