Browse Source

修改【客户初始化】MQ逻辑,增加异常处理,增加幂等判断

dev_shibei_match
wxz 5 years ago
parent
commit
153f62014f
  1. 13
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/mq/listener/InitCustomerOrgListener.java
  2. 10
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java
  3. 3
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/dao/CustomerHomeDao.java
  4. 13
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerCustomizeListener.java
  5. 7
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerHomeServiceImpl.java
  6. 6
      epmet-module/oper-customize/oper-customize-server/src/main/resources/mapper/CustomerHomeDao.xml
  7. 8
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java
  8. 5
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java
  9. 78
      epmet-user/epmet-user-server/src/main/java/com/epmet/mq/listener/InitCustomerRolesListener.java

13
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/mq/listener/InitCustomerOrgListener.java

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.constant.UserWorkType;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.form.AddAgencyAndStaffFormDTO;
@ -38,7 +40,16 @@ public class InitCustomerOrgListener implements RocketMQListener<MessageExt> {
String msg = new String(messageExt.getBody());
logger.info("初始化客户-初始化组织信息-收到消息内容:{}", msg);
InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class);
agencyService.saveRootAgency(constructRootAndAgencyDTO(msgObj));
try {
agencyService.saveRootAgency(constructRootAndAgencyDTO(msgObj));
} catch (RenException e) {
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
logger.error("【RocketMQ】初始化客户组织失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
} catch (Exception e) {
// 不是我们自己抛出的异常,可以让MQ重试
logger.error("【RocketMQ】初始化客户组织失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
throw e;
}
}
/**

10
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java

@ -351,7 +351,13 @@ public class AgencyServiceImpl implements AgencyService {
throw new RenException(EpmetErrorCode.OPER_ADD_CUSTOMER_ROOT_AGENCY_ERROR.getCode());
}
//3.查询客户具有指定RoleKey的角色信息
//3.调用epmet-user服务,初始化客户对应的角色;其内部会调用access服务给角色分配权限信息
Result initResult = epmetUserOpenFeignClient.initGovStaffRolesForCustomer(agencyDTO.getCustomerId());
if (!initResult.success()) {
throw new RenException("客户新增:调用user服务为客户初始化角色数据失败:".concat(initResult.toString()));
}
//4.查询客户具有指定RoleKey的角色信息
CustomerRoleFormDTO customerRoleForm = new CustomerRoleFormDTO();
customerRoleForm.setCustomerId(agencyDTO.getCustomerId());
customerRoleForm.setRoleKey(RoleKeyConstants.ROLE_KEY_ROOT_MANAGER);
@ -361,7 +367,7 @@ public class AgencyServiceImpl implements AgencyService {
throw new RenException("查询客户具有指定RoleKey的角色信息失败:".concat(getRoleResult.toString()));
}
//4.新增客户管理员信息
//5.新增客户管理员信息
StaffSubmitFromDTO staffSubmitFrom = ConvertUtils.sourceToTarget(staffDTO, StaffSubmitFromDTO.class);
staffSubmitFrom.setRoles(Arrays.asList(getRoleResult.getData().getId()));
staffSubmitFrom.setApp("gov");

3
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/dao/CustomerHomeDao.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.form.HomeDesignFormDTO;
import com.epmet.entity.CustomerHomeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -43,4 +44,6 @@ public interface CustomerHomeDao extends BaseDao<CustomerHomeEntity> {
* @date 2020/3/16 14:02
**/
List<CustomerHomeEntity> selectCustomerHomeList(HomeDesignFormDTO formDTO);
int countByCustomerId(@Param("customerId") String customerId);
}

13
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerCustomizeListener.java

@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.dto.CustomerHomeDTO;
import com.epmet.service.CustomerHomeService;
import org.apache.rocketmq.common.message.MessageExt;
@ -38,6 +40,15 @@ public class InitCustomerCustomizeListener implements RocketMQListener<MessageEx
CustomerHomeDTO customerHomeDTO = new CustomerHomeDTO();
customerHomeDTO.setCustomerId(msgObj.getCustomerId());
customerHomeService.init(customerHomeDTO);
try {
customerHomeService.init(customerHomeDTO);
} catch (RenException e) {
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
} catch (Exception e) {
// 不是我们自己抛出的异常,可以让MQ重试
logger.error("【RocketMQ】初始化客户组件失败:".concat(ExceptionUtils.getErrorStackTrace(e)));
throw e;
}
}
}

7
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/CustomerHomeServiceImpl.java

@ -20,6 +20,8 @@ package com.epmet.service.impl;
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.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant;
@ -119,6 +121,11 @@ public class CustomerHomeServiceImpl extends BaseServiceImpl<CustomerHomeDao, Cu
@Transactional(rollbackFor = Exception.class)
public void init(CustomerHomeDTO dto) {
int homeCount = baseDao.countByCustomerId(dto.getCustomerId());
if (homeCount > 0) {
throw new RenException("用户Home组件已存在,请勿重复初始化");
}
//居民端模板
List<CustomerHomeTemplateDTO> resiTempList = customerHomeTemplateService.getTemplateByClient(OperCustomizeConstant.RESIDENT);
//居民端草稿

6
epmet-module/oper-customize/oper-customize-server/src/main/resources/mapper/CustomerHomeDao.xml

@ -29,5 +29,11 @@
AND DEL_FLAG = '0'
</select>
<select id="countByCustomerId" resultType="java.lang.Integer">
select count(1)
from customer_home
where CUSTOMER_ID = #{customerId}
</select>
</mapper>

8
epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java

@ -469,4 +469,12 @@ public interface EpmetUserOpenFeignClient {
@PostMapping(value = "epmetuser/staffrole/specificrolesstaffs", consumes = MediaType.APPLICATION_JSON_VALUE)
Result<List<String>> specificRolesStaffs(RolesUsersListFormDTO rolesUsersListFormDTO);
/**
* 为客户初始化政府端工作人员角色
* @param customerId
* @return
*/
@PostMapping("/epmetuser/staffrole/initrolesforcustomer/{customerId}")
Result initGovStaffRolesForCustomer(@PathVariable String customerId);
}

5
epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java

@ -331,4 +331,9 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien
public Result<List<String>> specificRolesStaffs(RolesUsersListFormDTO rolesUsersListFormDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "specificRolesStaffs", rolesUsersListFormDTO);
}
@Override
public Result initGovStaffRolesForCustomer(String customerId) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "initGovStaffRolesForCustomer", customerId);
}
}

78
epmet-user/epmet-user-server/src/main/java/com/epmet/mq/listener/InitCustomerRolesListener.java

@ -1,39 +1,39 @@
package com.epmet.mq.listener;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
import com.epmet.service.GovStaffRoleService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 监听初始化客户动作为客户初始化角色列表
*/
@RocketMQMessageListener(topic = TopicConstants.INIT_CUSTOMER,
consumerGroup = ConsomerGroupConstants.INIT_CUSTOMER_ROLES_GROUP,
messageModel = MessageModel.CLUSTERING,
selectorExpression = "*")
@Component
public class InitCustomerRolesListener implements RocketMQListener<MessageExt> {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private GovStaffRoleService govStaffRoleService;
@Override
public void onMessage(MessageExt messageExt) {
String msg = new String(messageExt.getBody());
logger.info("初始化客户-初始化角色列表-收到消息内容:{}", msg);
InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class);
govStaffRoleService.initGovStaffRolesForCustomer(msgObj.getCustomerId());
}
}
//package com.epmet.mq.listener;
//
//import com.alibaba.fastjson.JSON;
//import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants;
//import com.epmet.commons.rocketmq.constants.TopicConstants;
//import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
//import com.epmet.service.GovStaffRoleService;
//import org.apache.rocketmq.common.message.MessageExt;
//import org.apache.rocketmq.spring.annotation.MessageModel;
//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
//import org.apache.rocketmq.spring.core.RocketMQListener;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
///**
// * 监听初始化客户动作,为客户初始化角色列表
// */
//@RocketMQMessageListener(topic = TopicConstants.INIT_CUSTOMER,
// consumerGroup = ConsomerGroupConstants.INIT_CUSTOMER_ROLES_GROUP,
// messageModel = MessageModel.CLUSTERING,
// selectorExpression = "*")
//@Component
//public class InitCustomerRolesListener implements RocketMQListener<MessageExt> {
//
// private Logger logger = LoggerFactory.getLogger(getClass());
//
// @Autowired
// private GovStaffRoleService govStaffRoleService;
//
// @Override
// public void onMessage(MessageExt messageExt) {
// String msg = new String(messageExt.getBody());
// logger.info("初始化客户-初始化角色列表-收到消息内容:{}", msg);
// InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class);
// govStaffRoleService.initGovStaffRolesForCustomer(msgObj.getCustomerId());
// }
//}

Loading…
Cancel
Save