|
|
@ -17,13 +17,37 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.FileCommonDTO; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.*; |
|
|
|
import com.epmet.dto.form.OrgCommonDTO; |
|
|
|
import com.epmet.dto.form.OrgStaffFormDTO; |
|
|
|
import com.epmet.dto.form.RoleStaffIdFormDTO; |
|
|
|
import com.epmet.dto.form.SendInfoFormDTO; |
|
|
|
import com.epmet.dto.result.SendInfoResultDTO; |
|
|
|
import com.epmet.entity.InfoAttEntity; |
|
|
|
import com.epmet.entity.InfoEntity; |
|
|
|
import com.epmet.entity.InfoProfileEntity; |
|
|
|
import com.epmet.entity.InfoReceiversEntity; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.service.InfoService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
/** |
|
|
|
* 消息主表 |
|
|
@ -48,6 +72,192 @@ public class InfoServiceImpl extends BaseServiceImpl<InfoDao, InfoEntity> implem |
|
|
|
private InfoReplyDao infoReplyDao; |
|
|
|
@Autowired |
|
|
|
private InfoReplyContentDao infoReplyContentDao; |
|
|
|
@Autowired |
|
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送消息 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return com.epmet.dto.result.SendInfoResultDTO |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/8/19 10:27 上午 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public SendInfoResultDTO sendInfo(SendInfoFormDTO formDTO) { |
|
|
|
//1、请先选择接收人
|
|
|
|
if (CollectionUtils.isEmpty(formDTO.getStaffIdList()) && |
|
|
|
CollectionUtils.isEmpty(formDTO.getOrgList()) && |
|
|
|
CollectionUtils.isEmpty(formDTO.getRoleIdList()) |
|
|
|
&& CollectionUtils.isEmpty(formDTO.getGroupIdList())) { |
|
|
|
throw new RenException(EpmetErrorCode.PLEASE_CHOOSE_RECEIVER.getCode(), EpmetErrorCode.PLEASE_CHOOSE_RECEIVER.getMsg()); |
|
|
|
} |
|
|
|
//2、选择的组织、角色、或者小组、是否有人呢??
|
|
|
|
Set<String> orgStaffIds=queryOrgStaffIds(formDTO.getCustomerId(),formDTO.getOrgList()); |
|
|
|
Set<String> roleStaffIds=queryRoleStaffIds(formDTO.getRoleIdList(),formDTO.getCustomerId()); |
|
|
|
Set<String> groupStaffIds = CollectionUtils.isNotEmpty(formDTO.getGroupIdList()) ? infoGroupReceiversDao.selectStaffIds(formDTO.getGroupIdList()) : Collections.EMPTY_SET; |
|
|
|
log.info("群组选择的人:"+JSON.toJSONString(groupStaffIds,true)); |
|
|
|
|
|
|
|
//3、计算接收人:
|
|
|
|
Set<String> totalReceiver=new LinkedHashSet<String>();; |
|
|
|
totalReceiver.addAll(formDTO.getStaffIdList()); |
|
|
|
totalReceiver.addAll(orgStaffIds); |
|
|
|
totalReceiver.addAll(roleStaffIds); |
|
|
|
totalReceiver.addAll(groupStaffIds); |
|
|
|
if(CollectionUtils.isEmpty(totalReceiver)){ |
|
|
|
throw new RenException(EpmetErrorCode.PLEASE_CHOOSE_RECEIVER.getCode(), EpmetErrorCode.PLEASE_CHOOSE_RECEIVER.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
//4、插入主表
|
|
|
|
InfoEntity infoEntity=constructInfoEntity(formDTO); |
|
|
|
baseDao.insert(infoEntity); |
|
|
|
//5、插入附件表
|
|
|
|
String firstAttId= StrConstant.EPMETY_STR; |
|
|
|
int sort=1; |
|
|
|
for (FileCommonDTO att : formDTO.getAttachmentList()) { |
|
|
|
InfoAttEntity infoAttEntity = new InfoAttEntity(); |
|
|
|
infoAttEntity.setInfoId(infoEntity.getId()); |
|
|
|
infoAttEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
infoAttEntity.setAttachmentFormat(att.getFormat()); |
|
|
|
infoAttEntity.setAttachmentName(att.getName()); |
|
|
|
infoAttEntity.setAttachmentType(att.getType()); |
|
|
|
infoAttEntity.setAttachmentUrl(att.getUrl()); |
|
|
|
infoAttEntity.setSort(sort); |
|
|
|
infoAttDao.insert(infoAttEntity); |
|
|
|
if(sort==1){ |
|
|
|
firstAttId=infoAttEntity.getId(); |
|
|
|
} |
|
|
|
sort++; |
|
|
|
} |
|
|
|
//6、接收人
|
|
|
|
totalReceiver.forEach(staffId->{ |
|
|
|
InfoReceiversEntity infoReceiversEntity=new InfoReceiversEntity(); |
|
|
|
infoReceiversEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
infoReceiversEntity.setInfoId(infoEntity.getId()); |
|
|
|
infoReceiversEntity.setStaffId(staffId); |
|
|
|
infoReceiversEntity.setReadFlag(false); |
|
|
|
infoReceiversDao.insert(infoReceiversEntity); |
|
|
|
|
|
|
|
}); |
|
|
|
//7、插入概要表
|
|
|
|
InfoProfileEntity infoProfileEntity=new InfoProfileEntity(); |
|
|
|
infoProfileEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
infoProfileEntity.setInfoId(infoEntity.getId()); |
|
|
|
if(infoEntity.getContent().length()>NumConstant.ONE_HUNDRED){ |
|
|
|
infoProfileEntity.setContent(StringUtils.substring(infoEntity.getContent(),NumConstant.NINETY_NINE)); |
|
|
|
}else{ |
|
|
|
infoProfileEntity.setContent(infoEntity.getContent()); |
|
|
|
} |
|
|
|
infoProfileEntity.setPublishStaffId(formDTO.getUserId()); |
|
|
|
infoProfileEntity.setTotalReceiver(totalReceiver.size()); |
|
|
|
infoProfileEntity.setFirstAttId(firstAttId); |
|
|
|
infoProfileEntity.setReadTotal(NumConstant.ZERO); |
|
|
|
infoProfileEntity.setUnReadReplyNum(NumConstant.ZERO); |
|
|
|
infoProfileEntity.setCreatedTime(infoEntity.getCreatedTime()); |
|
|
|
infoProfileEntity.setUpdatedTime(infoEntity.getUpdatedTime()); |
|
|
|
infoProfileDao.insert(infoProfileEntity); |
|
|
|
|
|
|
|
//8、发送站内信 todo
|
|
|
|
SendInfoResultDTO resultDTO=new SendInfoResultDTO(); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询架构里面的人 |
|
|
|
* |
|
|
|
* @param orgList |
|
|
|
* @return java.util.Set<java.lang.String> |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/8/19 11:34 上午 |
|
|
|
*/ |
|
|
|
private Set<String> queryOrgStaffIds(String customerId,Set<OrgCommonDTO> orgList) { |
|
|
|
if (CollectionUtils.isEmpty(orgList)) { |
|
|
|
return Collections.EMPTY_SET; |
|
|
|
} |
|
|
|
//如果我选择的是 东阿镇,是发送给本级及下级所有工作人员
|
|
|
|
OrgStaffFormDTO orgStaffFormDTO=new OrgStaffFormDTO(); |
|
|
|
orgStaffFormDTO.setCustomerId(customerId); |
|
|
|
for(OrgCommonDTO org:orgList){ |
|
|
|
if("grid".equals(org.getOrgType())){ |
|
|
|
orgStaffFormDTO.getGridIds().add(org.getOrgId()); |
|
|
|
}else if("agency".equals(org.getOrgType())){ |
|
|
|
orgStaffFormDTO.getAgencyIds().add(org.getOrgId()); |
|
|
|
}else if("dept".equals(org.getOrgType())){ |
|
|
|
orgStaffFormDTO.getDeptIds().add(org.getOrgId()); |
|
|
|
} |
|
|
|
} |
|
|
|
Result<Set<String>> result=govOrgOpenFeignClient.queryOrgStaffs(orgStaffFormDTO); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException("根据组织查询工作人员异常"); |
|
|
|
} |
|
|
|
if(CollectionUtils.isEmpty(result.getData())){ |
|
|
|
log.info("已选择的架构里没有工作人员"); |
|
|
|
return Collections.EMPTY_SET; |
|
|
|
} |
|
|
|
return result.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询角色里面的人 |
|
|
|
* |
|
|
|
* @param roleIdList |
|
|
|
* @param customerId |
|
|
|
* @return java.util.Set<java.lang.String> |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/8/19 11:34 上午 |
|
|
|
*/ |
|
|
|
private Set<String> queryRoleStaffIds(Set<String> roleIdList, String customerId) { |
|
|
|
if (CollectionUtils.isEmpty(roleIdList)) { |
|
|
|
return Collections.EMPTY_SET; |
|
|
|
} |
|
|
|
RoleStaffIdFormDTO formDTO = new RoleStaffIdFormDTO(); |
|
|
|
formDTO.setCustomerId(customerId); |
|
|
|
formDTO.setRoleIds(roleIdList); |
|
|
|
Result<Set<String>> result = epmetUserOpenFeignClient.queryRoleStaffIds(formDTO); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException("根据角色查询工作人员异常"); |
|
|
|
} |
|
|
|
if(CollectionUtils.isEmpty(result.getData())){ |
|
|
|
log.info("角色下没有工作人员"); |
|
|
|
return Collections.EMPTY_SET; |
|
|
|
} |
|
|
|
return result.getData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 构造主表 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return com.epmet.entity.InfoEntity |
|
|
|
* @author yinzuomei |
|
|
|
* @date 2021/8/19 10:38 上午 |
|
|
|
*/ |
|
|
|
private InfoEntity constructInfoEntity(SendInfoFormDTO formDTO) { |
|
|
|
InfoEntity infoEntity=new InfoEntity(); |
|
|
|
infoEntity.setContent(formDTO.getContent()); |
|
|
|
infoEntity.setPublishStaffId(formDTO.getUserId()); |
|
|
|
infoEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
return infoEntity; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |