Merge branch 'feature/REQ-1507' of axzsource.com:universal/infrastructure/backend/msg-center-plat into pre
This commit is contained in:
commit
aadd5390e2
@ -1,14 +1,20 @@
|
||||
package cn.axzo.msg.center.message.controller;
|
||||
|
||||
import cn.axzo.msg.center.dal.MessageBaseTemplateDao;
|
||||
import cn.axzo.msg.center.dal.MessageRouteDetailDao;
|
||||
import cn.axzo.msg.center.dal.MessageRouterConfigDao;
|
||||
import cn.axzo.msg.center.dal.MessageTemplateRouterDao;
|
||||
import cn.axzo.msg.center.dal.PendingMessageRecordDao;
|
||||
import cn.axzo.msg.center.domain.entity.MessageBaseTemplate;
|
||||
import cn.axzo.msg.center.domain.entity.MessageRouteDetail;
|
||||
import cn.axzo.msg.center.domain.entity.MessageRouterConfig;
|
||||
import cn.axzo.msg.center.domain.entity.MessageTemplateRouter;
|
||||
import cn.axzo.msg.center.domain.entity.PendingMessageRecord;
|
||||
import cn.axzo.msg.center.message.service.PendingMessageDataInitService;
|
||||
import cn.axzo.msg.center.service.admin.MessageAdminConsoleClient;
|
||||
import cn.axzo.msg.center.service.enums.BizCategoryEnum;
|
||||
import cn.axzo.msg.center.service.enums.BizDetailShowStrategyEnum;
|
||||
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -16,10 +22,13 @@ import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -39,6 +48,8 @@ public class MessageAdminController implements MessageAdminConsoleClient {
|
||||
private final MessageTemplateRouterDao messageTemplateRouterDao;
|
||||
private final MessageRouteDetailDao messageRouteDetailDao;
|
||||
private final MessageRouterConfigDao messageRouterConfigDao;
|
||||
private final MessageBaseTemplateDao messageBaseTemplateDao;
|
||||
private final PendingMessageRecordDao pendingMessageRecordDao;
|
||||
|
||||
@Override
|
||||
public CommonResponse<Void> transformPendingMessageRecord(Integer diffDays, Long minRecordId) {
|
||||
@ -46,6 +57,21 @@ public class MessageAdminController implements MessageAdminConsoleClient {
|
||||
return CommonResponse.success();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/admin/console/template/category/adjust", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
public CommonResponse<Void> adjustTemplateCategory(@RequestParam Long id) {
|
||||
if (Objects.isNull(id)) {
|
||||
return CommonResponse.success();
|
||||
}
|
||||
messageBaseTemplateDao.lambdaUpdate()
|
||||
.eq(MessageBaseTemplate::getId, id)
|
||||
.set(MessageBaseTemplate::getMsgCategory, MessageCategoryEnum.APPROVAL_PENDING_MESSAGE)
|
||||
.update();
|
||||
pendingMessageRecordDao.lambdaUpdate()
|
||||
.eq(PendingMessageRecord::getBizCategory, BizCategoryEnum.FLOW)
|
||||
.lt(PendingMessageRecord::getCreateAt, new Date(1700411318));
|
||||
return CommonResponse.success();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/admin/console/template/init-router", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CommonResponse<Void> initTemplateRouter() {
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
package cn.axzo.msg.center.message.service.impl;
|
||||
|
||||
import cn.axzo.apollo.core.web.Result;
|
||||
import cn.axzo.apollo.workspace.api.workspace.OrganizationalNodePractitionerWideApi;
|
||||
import cn.axzo.apollo.workspace.api.workspace.req.OrganizationalNodePractitionerWideReqParams;
|
||||
import cn.axzo.apollo.workspace.api.workspace.res.OrganizationalNodePractitionerWideDto;
|
||||
import cn.axzo.framework.core.util.MapUtil;
|
||||
import cn.axzo.msg.center.api.enums.MsgTypeEnum;
|
||||
import cn.axzo.msg.center.common.exception.ServiceException;
|
||||
import cn.axzo.msg.center.dal.MessageRecordDao;
|
||||
@ -17,17 +22,19 @@ import cn.axzo.msg.center.service.enums.PendingMessageStateEnum;
|
||||
import cn.axzo.msg.center.utils.DateFormatUtil;
|
||||
import cn.axzo.msg.center.utils.PersonIdentityUtil;
|
||||
import cn.axzo.msg.center.utils.UUIDUtil;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -43,8 +50,9 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PendingMessageDataInitServiceImpl implements PendingMessageDataInitService {
|
||||
@Resource
|
||||
private Environment environment;
|
||||
|
||||
private final Environment environment;
|
||||
private final OrganizationalNodePractitionerWideApi organizationalNodePractitionerWideApi;
|
||||
|
||||
private static final PersonDTO SYSTEM = PersonDTO.builder()
|
||||
.id(0L)
|
||||
@ -67,14 +75,15 @@ public class PendingMessageDataInitServiceImpl implements PendingMessageDataInit
|
||||
.lt(MessageRecord::getId, scrollId)
|
||||
.gt(MessageRecord::getId, minRecordId)
|
||||
.orderByDesc(MessageRecord::getId)
|
||||
.last("LIMIT 1000")
|
||||
.last("LIMIT 2000")
|
||||
.list();
|
||||
final Map<String, Long> ouIdMap = Maps.newHashMap();
|
||||
while (!records.isEmpty()) {
|
||||
String profile = environment.getProperty("spring.profiles.active");
|
||||
if ("test".equals(profile) || "master".equals(profile)) {
|
||||
batchSavePendingMessage(records);
|
||||
if ("dev".equals(profile)) {
|
||||
log.warn("系统环境[" + profile + "],不支持该接口操作");
|
||||
} else {
|
||||
log.warn("目前只有测试test环境和生产master环境支持该操作!");
|
||||
batchSavePendingMessage(records, ouIdMap);
|
||||
}
|
||||
scrollId = records.stream().min(Comparator.comparing(MessageRecord::getId))
|
||||
.map(MessageRecord::getId).orElse(0L);
|
||||
@ -86,12 +95,12 @@ public class PendingMessageDataInitServiceImpl implements PendingMessageDataInit
|
||||
.lt(MessageRecord::getId, scrollId)
|
||||
.gt(MessageRecord::getId, minRecordId)
|
||||
.orderByDesc(MessageRecord::getId)
|
||||
.last("LIMIT 1000")
|
||||
.last("LIMIT 2000")
|
||||
.list();
|
||||
}
|
||||
}
|
||||
|
||||
private void batchSavePendingMessage(List<MessageRecord> records) {
|
||||
private void batchSavePendingMessage(List<MessageRecord> records, Map<String, Long> ouIdMap) {
|
||||
if (CollectionUtils.isEmpty(records)) {
|
||||
return;
|
||||
}
|
||||
@ -100,10 +109,50 @@ public class PendingMessageDataInitServiceImpl implements PendingMessageDataInit
|
||||
.filter(e -> StringUtils.isNotBlank(e.getTemplateCode()))
|
||||
.collect(Collectors.toList());
|
||||
log.info("[cold_blade] transform rows:[{}]", pendingMessageRecords.size());
|
||||
Map<String, Long> executorIdWorkspceIdMap = pendingMessageRecords.stream()
|
||||
.filter(e -> Objects.equals(e.getExecutorType(), IdentityTypeEnum.PRACTITIONER))
|
||||
.filter(e -> !ouIdMap.containsKey(getKey(e)))
|
||||
.collect(Collectors.toMap(this::getKey, PendingMessageRecord::getExecutorId, (cur, next) -> next));
|
||||
Map<String, Long> map = fetchOuId(executorIdWorkspceIdMap);
|
||||
if (MapUtil.isNotEmpty(map)) {
|
||||
ouIdMap.putAll(map);
|
||||
}
|
||||
// 设置ouId
|
||||
pendingMessageRecords.stream()
|
||||
.filter(e -> Objects.equals(e.getExecutorType(), IdentityTypeEnum.PRACTITIONER))
|
||||
.filter(e -> ouIdMap.containsKey(getKey(e)))
|
||||
.forEach(e -> e.setOuId(ouIdMap.get(getKey(e))));
|
||||
//批量插入数据库
|
||||
pendingMessageRecordDao.saveOrUpdateBatch(pendingMessageRecords);
|
||||
}
|
||||
|
||||
private Map<String, Long> fetchOuId(Map<String, Long> executorIdWorkspceIdMap) {
|
||||
if (MapUtil.isEmpty(executorIdWorkspceIdMap)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
OrganizationalNodePractitionerWideReqParams param = new OrganizationalNodePractitionerWideReqParams();
|
||||
param.setIdentityIds(Lists.newArrayList(executorIdWorkspceIdMap.values()));
|
||||
Result<List<OrganizationalNodePractitionerWideDto>> result = organizationalNodePractitionerWideApi.getList(param);
|
||||
if (CollectionUtils.isEmpty(result.getData())) {
|
||||
log.info("errCode:[{}], msg:{}", result.getCode(), result.getMsg());
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, List<OrganizationalNodePractitionerWideDto>> groupingBy = result.getData().stream()
|
||||
.filter(e -> executorIdWorkspceIdMap.containsKey(getKey(e)))
|
||||
.collect(Collectors.groupingBy(this::getKey));
|
||||
return groupingBy.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get(0).getOrganizationalUnitId()));
|
||||
}
|
||||
|
||||
private String getKey(PendingMessageRecord record) {
|
||||
return record.getExecutorId() + "_" + record.getOrgId();
|
||||
}
|
||||
|
||||
private String getKey(OrganizationalNodePractitionerWideDto dto) {
|
||||
return dto.getIdentityId() + "_" + dto.getWorkspaceId();
|
||||
}
|
||||
|
||||
private PendingMessageRecord convert(MessageRecord record) {
|
||||
PendingMessageRecord pendingMsgRecord = new PendingMessageRecord();
|
||||
pendingMsgRecord.setPromoterPersonId(SYSTEM.getId());
|
||||
@ -135,13 +184,12 @@ public class PendingMessageDataInitServiceImpl implements PendingMessageDataInit
|
||||
}
|
||||
|
||||
private String getTemplateCode(Long relationId) {
|
||||
// TODO: [zuoqinbo]
|
||||
// 需要通过映射表获取 https://alidocs.dingtalk.com/i/nodes/YndMj49yWj7q1dB9h793q5dKV3pmz5aA?iframeQuery=utm_source%3Dportal%26utm_medium%3Dportal_recent
|
||||
String profile = environment.getProperty("spring.profiles.active");
|
||||
if ("test".equals(profile) || "master".equals(profile)) {
|
||||
return msgTemplateMap.get(Integer.parseInt(String.valueOf(relationId)));
|
||||
if ("dev".equals(profile)) {
|
||||
throw new ServiceException("系统环境[" + profile + "],不支持该接口操作");
|
||||
}
|
||||
throw new ServiceException("系统环境[" + profile + "],不支持该接口操作");
|
||||
return msgTemplateMap.get(Integer.parseInt(String.valueOf(relationId)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,4 +222,7 @@ public class PendingMessageDataInitServiceImpl implements PendingMessageDataInit
|
||||
msgTemplateMap.put(564, "fc35f169515e43e39d863b34e5226e5e");
|
||||
}
|
||||
|
||||
private static final ImmutableSet<Integer> EXCLUDE_WORKSPACE_IDS = ImmutableSet.of(3, 5, 16, 17, 19, 21, 50, 75, 105,
|
||||
106, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 119, 120, 122, 123, 124, 125, 126, 131, 132, 140, 141,
|
||||
142, 148, 153, 197, 216, 236, 237, 238, 248, 275, 213, 214, 226, 239, 240, 246, 260, 266, 267, 3398);
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package cn.axzo.msg.center.message.service.impl;
|
||||
|
||||
import cn.axzo.apollo.core.web.Result;
|
||||
import cn.axzo.apollo.workspace.api.workspace.OrganizationalNodePractitionerWideApi;
|
||||
import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
||||
import cn.axzo.apollo.workspace.api.workspace.req.OrganizationalNodePractitionerWideReqParams;
|
||||
import cn.axzo.apollo.workspace.api.workspace.res.OrganizationalNodePractitionerWideDto;
|
||||
import cn.axzo.apollo.workspace.api.workspace.res.SimpleWorkspaceRes;
|
||||
import cn.axzo.framework.core.util.MapUtil;
|
||||
import cn.axzo.msg.center.api.enums.MsgRecordTerminalTypeEnum;
|
||||
@ -52,6 +55,7 @@ import cn.axzo.msg.center.utils.MessageRouterUtil;
|
||||
import cn.axzo.msg.center.utils.OrderFieldParseUtil;
|
||||
import cn.axzo.msg.center.utils.UUIDUtil;
|
||||
import cn.azxo.framework.common.model.Page;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
@ -90,6 +94,7 @@ public class PendingMessageNewServiceImpl implements PendingMessageNewService {
|
||||
private final MessageTemplateNewService messageTemplateNewService;
|
||||
private final MessageTemplateGroupService messageTemplateGroupService;
|
||||
private final WorkspaceApi workspaceApi;
|
||||
private final OrganizationalNodePractitionerWideApi organizationalNodePractitionerWideApi;
|
||||
|
||||
@Override
|
||||
public List<PendingMessageStatisticDTO> groupStatistic(MessageGroupNodeStatisticParam param) {
|
||||
@ -186,9 +191,11 @@ public class PendingMessageNewServiceImpl implements PendingMessageNewService {
|
||||
public Page<MessageDetailRes> compatiblePageQuery(PendingMessagePageRequest request) {
|
||||
List<String> groupTreeRootNodeCodes = messageGroupNodeService
|
||||
.listGroupTreeRootNodeCodes(MessageGroupCategoryEnum.PENDING, request.getAppTerminalType());
|
||||
PendingMessageStateEnum pendingMessageState = fetchPendingMessageState(request.getRoleCategory(), request.getMsgState());
|
||||
PersonDTO operator = PersonDTO.from(request.getPersonId(), request.getIdentityId(), request.getIdentityType());
|
||||
// 开始构建分页查询条件
|
||||
LambdaQueryChainWrapper<PendingMessageRecord> query = pendingMessageRecordDao.lambdaQuery();
|
||||
LambdaQueryChainWrapper<PendingMessageRecord> query = pendingMessageRecordDao.lambdaQuery()
|
||||
.eq(Objects.nonNull(pendingMessageState), PendingMessageRecord::getState, pendingMessageState);
|
||||
// 构建人维度的查询条件
|
||||
buildPersonCondition(query, request.getWithIdentify(), request.getRoleCategory(), operator);
|
||||
// 模板的分类,对代办进行分组过滤
|
||||
@ -530,7 +537,7 @@ public class PendingMessageNewServiceImpl implements PendingMessageNewService {
|
||||
record.setRequestNo(requestNo);
|
||||
record.setState(PendingMessageStateEnum.HAS_BEEN_SENT);
|
||||
// 构建代办记录的人维度的相关信息
|
||||
buildPersonInfo(record, param.getPromoter(), executor);
|
||||
buildPersonInfo(record, param.getPromoter(), executor, workspace.getId());
|
||||
// 构建模板信息
|
||||
buildTemplateInfo(record, msgTemplate, param.getBizExtParams());
|
||||
// 构建代办所属企业/项目等相关信息
|
||||
@ -545,7 +552,7 @@ public class PendingMessageNewServiceImpl implements PendingMessageNewService {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void buildPersonInfo(PendingMessageRecord record, PersonDTO promoter, PersonDTO executor) {
|
||||
private void buildPersonInfo(PendingMessageRecord record, PersonDTO promoter, PersonDTO executor, Long workspaceId) {
|
||||
record.setPromoterId(promoter.getIdentity().getId());
|
||||
record.setPromoterType(promoter.getIdentity().getType());
|
||||
record.setPromoterPersonId(promoter.getId());
|
||||
@ -554,9 +561,28 @@ public class PendingMessageNewServiceImpl implements PendingMessageNewService {
|
||||
record.setExecutorType(executor.getIdentity().getType());
|
||||
record.setExecutorPersonId(executor.getId());
|
||||
record.setExecutorName(executor.getName());
|
||||
// 执行人身份是从业人员,查询ouId
|
||||
record.setOuId(getPractitionOuId(executor, workspaceId));
|
||||
|
||||
}
|
||||
|
||||
private Long getPractitionOuId(PersonDTO executor, Long workspaceId) {
|
||||
|
||||
// 从业人员需要获取ouId
|
||||
if (IdentityTypeEnum.PRACTITIONER == executor.getIdentity().getType()) {
|
||||
OrganizationalNodePractitionerWideReqParams param = new OrganizationalNodePractitionerWideReqParams();
|
||||
param.setWorkspaceId(workspaceId);
|
||||
param.setIdentityId(executor.getIdentity().getId());
|
||||
log.info("get ouId params->{}", JSON.toJSONString(param));
|
||||
Result<OrganizationalNodePractitionerWideDto> result = organizationalNodePractitionerWideApi.getOne(param);
|
||||
log.info("get ouId result->{}", JSON.toJSONString(result));
|
||||
if (null != result && null != result.getData() && null != result.getData().getOrganizationalUnitId()) {
|
||||
return result.getData().getOrganizationalUnitId();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void buildTemplateInfo(PendingMessageRecord record, MessageTemplateDTO msgTemplate, String bizParam) {
|
||||
JSONObject bizExtParam = JSONObjectUtil.parseObject(bizParam);
|
||||
String title = PlaceholderResolver
|
||||
|
||||
@ -36,7 +36,7 @@ public interface MessageAdminConsoleClient {
|
||||
* @return 消息的唯一标识
|
||||
*/
|
||||
@PostMapping("/admin/console/transform")
|
||||
CommonResponse<Void> transformPendingMessageRecord(@RequestParam(required = true) Integer diffDays,
|
||||
@RequestParam(required = true) Long minRecordId);
|
||||
CommonResponse<Void> transformPendingMessageRecord(@RequestParam Integer diffDays,
|
||||
@RequestParam Long minRecordId);
|
||||
|
||||
}
|
||||
|
||||
@ -96,6 +96,10 @@ public class PendingMessagePageRequest extends PageRequest implements Serializab
|
||||
* 工作台id
|
||||
*/
|
||||
private Long workspaceId;
|
||||
/**
|
||||
* 单位id
|
||||
*/
|
||||
private Long ouId;
|
||||
/**
|
||||
* 排序字段集合
|
||||
*/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.msg.center.notices.client.handler;
|
||||
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.msg.center.notices.common.enums.ReturnCodeEnum;
|
||||
import cn.axzo.msg.center.notices.common.exception.BizException;
|
||||
import cn.axzo.msg.center.notices.integration.client.DingDingClient;
|
||||
@ -11,6 +12,7 @@ import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ -22,7 +24,7 @@ import javax.annotation.Resource;
|
||||
* @since 2021-05-17 15:44
|
||||
*/
|
||||
@Slf4j
|
||||
/*@RestControllerAdvice*/
|
||||
@RestControllerAdvice
|
||||
public class ControllerExceptionHandler {
|
||||
|
||||
@Resource(name = "dingDingClient")
|
||||
@ -34,6 +36,12 @@ public class ControllerExceptionHandler {
|
||||
return CommonResponse.error(e.getBizCode(), e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = ServiceException.class)
|
||||
public CommonResponse bizException(ServiceException e){
|
||||
log.warn("[mns] ControllerExceptionHandler.bizException Exception", e);
|
||||
return CommonResponse.error(e.getErrorCode(), e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = IllegalArgumentException.class)
|
||||
public CommonResponse handleIllegalArgumentException(IllegalArgumentException e) {
|
||||
LogUtil.error("[mns] ControllerExceptionHandler.handleIllegalArgumentException Exception message ", e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user