|
|
@@ -0,0 +1,184 @@ |
|
|
|
package com.hz.pm.api.open.manage; |
|
|
|
|
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.hz.pm.api.expert.model.dto.DictionaryVO; |
|
|
|
import com.hz.pm.api.meta.model.dto.DictionaryDTO; |
|
|
|
import com.hz.pm.api.user.model.entity.UserInfo; |
|
|
|
import com.hz.pm.api.user.security.model.UserFullInfoDTO; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.google.common.collect.Sets; |
|
|
|
import com.hz.pm.api.common.helper.UserInfoHelper; |
|
|
|
import com.hz.pm.api.meeting.entity.domain.Meeting; |
|
|
|
import com.hz.pm.api.meeting.entity.domain.MeetingExpert; |
|
|
|
import com.hz.pm.api.meeting.service.IMeetingExpertService; |
|
|
|
import com.hz.pm.api.meeting.service.IMeetingService; |
|
|
|
import com.hz.pm.api.meta.constant.ExpertDictTypeEnum; |
|
|
|
import com.hz.pm.api.meta.helper.DictionaryCache; |
|
|
|
import com.hz.pm.api.meta.model.entity.ExpertDictionary; |
|
|
|
import com.hz.pm.api.meta.service.IExpertDictionaryService; |
|
|
|
import com.hz.pm.api.open.model.po.ReqMeetingExpertInfoPO; |
|
|
|
import com.hz.pm.api.open.model.vo.ExpertInfoVO; |
|
|
|
import com.hz.pm.api.open.model.vo.MeetingExpertInfoVO; |
|
|
|
import com.hz.pm.api.user.service.IUserInfoService; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author CMM |
|
|
|
* @since 2024/05/10 17:18 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class OpenApiMeetingExpertInfoManage { |
|
|
|
|
|
|
|
@Value("${hz-pm.interfaceKey}") |
|
|
|
private String meetingExpertInfoKey; |
|
|
|
|
|
|
|
private final IMeetingService meetingService; |
|
|
|
private final IMeetingExpertService meetingExpertService; |
|
|
|
private final UserInfoHelper userInfoHelper; |
|
|
|
private final IUserInfoService userInfoService; |
|
|
|
private final IExpertDictionaryService iExpertDictionaryService; |
|
|
|
private final DictionaryCache dictionaryCache; |
|
|
|
public List<MeetingExpertInfoVO> infoList(ReqMeetingExpertInfoPO po) { |
|
|
|
String key = po.getKey(); |
|
|
|
// 校验传入的签名 |
|
|
|
if (!checkSign(key)){ |
|
|
|
throw new BizException("签名错误!"); |
|
|
|
} |
|
|
|
// 获取已经抽取完成 确认参加会议并且未签到的专家信息 |
|
|
|
List<Meeting> meetingList = meetingService.list(Wrappers.lambdaQuery(Meeting.class) |
|
|
|
.eq(Meeting::getConfirmedRoster, true)); |
|
|
|
if(CollUtil.isEmpty(meetingList)){ |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
List<MeetingExpertInfoVO> result = Lists.newArrayList(); |
|
|
|
// 获取已抽取完成会议中未签到的专家信息 |
|
|
|
List<Long> meetingIds = meetingList.stream().map(Meeting::getId).collect(Collectors.toList()); |
|
|
|
Map<Long, List<MeetingExpert>> meetingExpertMap = meetingExpertService.list(Wrappers.lambdaQuery(MeetingExpert.class) |
|
|
|
.in(MeetingExpert::getMeetingId, meetingIds) |
|
|
|
.eq(MeetingExpert::getSignStatus, Boolean.FALSE)) |
|
|
|
.stream().collect(Collectors.groupingBy(MeetingExpert::getMeetingId)); |
|
|
|
Map<Long, Meeting> meetingMap = CollUtils.listToMap(meetingList, Meeting::getId); |
|
|
|
List<MeetingExpert> experts = Lists.newArrayList(); |
|
|
|
for (Map.Entry<Long, List<MeetingExpert>> listEntry : meetingExpertMap.entrySet()) { |
|
|
|
List<MeetingExpert> value = listEntry.getValue(); |
|
|
|
experts.addAll(value); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取未签到的专家信息 |
|
|
|
List<MeetingExpert> expertList = experts.stream().filter(m -> Boolean.FALSE.equals(m.getSignStatus())).collect(Collectors.toList()); |
|
|
|
Set<Long> userIds = expertList.stream().map(MeetingExpert::getExpertId).collect(Collectors.toSet()); |
|
|
|
List<UserInfo> userInfoList = userInfoService.list(Wrappers.lambdaQuery(UserInfo.class).in(UserInfo::getId, userIds)); |
|
|
|
Set<String> employeeSet = Sets.newHashSet(); |
|
|
|
userInfoList = userInfoList.stream().filter(u -> employeeSet.add(u.getEmployeeCode())).collect(Collectors.toList()); |
|
|
|
List<UserFullInfoDTO> userFullInfos = userInfoHelper.getUserFullInfos(userInfoList); |
|
|
|
Set<Long> userIdSet = Sets.newHashSet(); |
|
|
|
userFullInfos = userFullInfos.stream().filter(u -> userIdSet.add(u.getUserId())).collect(Collectors.toList()); |
|
|
|
Map<Long, UserFullInfoDTO> infoMap = userFullInfos.stream().collect(Collectors.toMap(UserFullInfoDTO::getUserId, v -> v)); |
|
|
|
|
|
|
|
List<ExpertDictionary> expertDictionaryList = iExpertDictionaryService.list(Wrappers.lambdaQuery(ExpertDictionary.class) |
|
|
|
.eq(ExpertDictionary::getExpertInfoField, ExpertDictTypeEnum.EXPERT_TYPE.getKey()) |
|
|
|
.in(ExpertDictionary::getUserId, userIdSet)); |
|
|
|
Map<Long, List<ExpertDictionary>> dictMap = expertDictionaryList.stream().collect(Collectors.groupingBy(ExpertDictionary::getUserId)); |
|
|
|
|
|
|
|
for (Map.Entry<Long, List<MeetingExpert>> entry : meetingExpertMap.entrySet()) { |
|
|
|
MeetingExpertInfoVO vo = new MeetingExpertInfoVO(); |
|
|
|
Long meetingId = entry.getKey(); |
|
|
|
Meeting meeting = meetingMap.get(meetingId); |
|
|
|
if (Objects.nonNull(meeting)){ |
|
|
|
vo.setMeetingId(meeting.getId()); |
|
|
|
vo.setStartTime(meeting.getStartTime()); |
|
|
|
vo.setEndTime(meeting.getEndTime()); |
|
|
|
vo.setMeetingName(meeting.getName()); |
|
|
|
vo.setMeetingAddress(meeting.getMeetingAddress()); |
|
|
|
vo.setConnecter(meeting.getConnecter()); |
|
|
|
vo.setContact(meeting.getContact()); |
|
|
|
} |
|
|
|
List<MeetingExpert> meetingExperts = entry.getValue(); |
|
|
|
if (CollUtil.isNotEmpty(meetingExperts)){ |
|
|
|
// 获取未签到的专家信息 |
|
|
|
List<MeetingExpert> expertUserList = meetingExperts.stream().filter(m -> Boolean.FALSE.equals(m.getSignStatus())).collect(Collectors.toList()); |
|
|
|
if (CollUtil.isNotEmpty(expertUserList)){ |
|
|
|
List<ExpertInfoVO> expertInfoVOList = expertUserList.stream().map(m -> { |
|
|
|
ExpertInfoVO expertInfoVO = new ExpertInfoVO(); |
|
|
|
expertInfoVO.setUserId(m.getExpertId()); |
|
|
|
expertInfoVO.setName(m.getExpertName()); |
|
|
|
expertInfoVO.setPhoneNo(m.getMobile()); |
|
|
|
UserFullInfoDTO userFullInfoDTO = infoMap.get(m.getExpertId()); |
|
|
|
if (Objects.nonNull(userFullInfoDTO)){ |
|
|
|
expertInfoVO.setMhUnitId(userFullInfoDTO.getMhUnitId()); |
|
|
|
expertInfoVO.setMhUnitName(userFullInfoDTO.getMhUnitName()); |
|
|
|
} |
|
|
|
List<ExpertDictionary> dictionaries = dictMap.get(m.getExpertId()); |
|
|
|
if (CollUtil.isNotEmpty(dictionaries)){ |
|
|
|
List<DictionaryVO> dictionaryFieldInfos = dictionaries.stream().map(r -> { |
|
|
|
DictionaryVO dictionary = new DictionaryVO(); |
|
|
|
dictionary.setDictionaryType(r.getExpertInfoField()); |
|
|
|
dictionary.setDictionaryCode(r.getDictionaryCode()); |
|
|
|
Optional<DictionaryDTO> dictionaryDTO = dictionaryCache.getByCode(r.getDictionaryCode()); |
|
|
|
dictionaryDTO.ifPresent(dictDTO -> dictionary.setDictionaryName(dictDTO.getName())); |
|
|
|
return dictionary; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
expertInfoVO.setExpertType(dictionaryFieldInfos); |
|
|
|
} |
|
|
|
return expertInfoVO; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
vo.setExpertInfoList(expertInfoVOList); |
|
|
|
} |
|
|
|
} |
|
|
|
result.add(vo); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private Boolean checkSign(String key) { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
sb.append("key=").append(meetingExpertInfoKey); |
|
|
|
// 使用SHA-256进行加密 |
|
|
|
String sign = null; |
|
|
|
try { |
|
|
|
MessageDigest md = MessageDigest.getInstance("SHA-256"); |
|
|
|
byte[] bytes = md.digest(sb.toString().getBytes()); |
|
|
|
sign = bytesToHexString(bytes); |
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
if (sign == null || sign.length() <= 8) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
String signStr = sign.substring(sign.length() - 8); |
|
|
|
return signStr.equals(key); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将字节数组转换为十六进制字符串 |
|
|
|
* |
|
|
|
* @param bytes 字节数组 |
|
|
|
* @return 十六进制字符串 |
|
|
|
*/ |
|
|
|
private static String bytesToHexString(byte[] bytes) { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (byte b : bytes) { |
|
|
|
String hex = Integer.toHexString(b & 0xFF); |
|
|
|
if (hex.length() == 1) { |
|
|
|
sb.append("0"); |
|
|
|
} |
|
|
|
sb.append(hex); |
|
|
|
} |
|
|
|
return sb.toString(); |
|
|
|
} |
|
|
|
} |