Browse Source

引入Rocketmq

修改客户初始化操作,使用rocketmq发送消息完成初始化
dev
wxz 5 years ago
parent
commit
1ec667b71a
  1. 21
      epmet-commons/epmet-commons-rocketmq/pom.xml
  2. 21
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java
  3. 5
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java
  4. 148
      epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/InitCustomerMQMsg.java
  5. 1
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  6. 1
      epmet-commons/pom.xml
  7. 7
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageSendApproach.java
  8. 13
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java
  9. 15
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/SystemMsgFormDTO.java
  10. 10
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/feign/EpmetMessageOpenFeignClient.java
  11. 6
      epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/feign/fallback/EpmetMessageOpenFeignClientFallback.java
  12. 7
      epmet-module/epmet-message/epmet-message-server/pom.xml
  13. 27
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/SystemMessageController.java
  14. 33
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/SystemMessageDao.java
  15. 57
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/entity/SystemMessageEntity.java
  16. 7
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/SystemMessageService.java
  17. 70
      epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java
  18. 7
      epmet-module/epmet-message/epmet-message-server/src/main/resources/bootstrap.yml
  19. 18
      epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/SystemMessageDao.xml
  20. 6
      epmet-module/gov-org/gov-org-server/pom.xml
  21. 76
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/mq/listener/InitCustomerOrgListener.java
  22. 5
      epmet-module/gov-org/gov-org-server/src/main/resources/bootstrap.yml
  23. 12
      epmet-module/oper-crm/oper-crm-server/pom.xml
  24. 124
      epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java
  25. 7
      epmet-module/oper-customize/oper-customize-server/pom.xml
  26. 43
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/mq/listener/InitCustomerCustomizeListener.java
  27. 5
      epmet-module/oper-customize/oper-customize-server/src/main/resources/bootstrap.yml
  28. 6
      epmet-user/epmet-user-server/pom.xml
  29. 39
      epmet-user/epmet-user-server/src/main/java/com/epmet/mq/listener/InitCustomerRolesListener.java
  30. 5
      epmet-user/epmet-user-server/src/main/resources/bootstrap.yml

21
epmet-commons/epmet-commons-rocketmq/pom.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>epmet-commons</artifactId>
<groupId>com.epmet</groupId>
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>epmet-commons-rocketmq</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
</project>

21
epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java

@ -0,0 +1,21 @@
package com.epmet.commons.rocketmq.constants;
/**
* 消费者组常量
*/
public interface ConsomerGroupConstants {
/**
* 初始化客户角色消费者组
*/
String INIT_CUSTOMER_ROLES_GROUP = "init_customer_roles_group";
/**
* 初始化客户自定义消费者组
*/
String INIT_CUSTOMER_CUSTOMIZE_GROUP = "init_customer_customize_group";
/**
* 初始化客户组织机构信息分组
*/
String INIT_CUSTOMER_ORG_GROUP = "init_customer_org_group";
}

5
epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java

@ -0,0 +1,5 @@
package com.epmet.commons.rocketmq.constants;
public interface TopicConstants {
String INIT_CUSTOMER = "init_customer_topic";
}

148
epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/InitCustomerMQMsg.java

@ -0,0 +1,148 @@
package com.epmet.commons.rocketmq.messages;
public class InitCustomerMQMsg {
private String customerId;
private InitCustomerAgency agency;
private InitCustomerStaff staff;
public static class InitCustomerStaff {
private String agencyId;
private Integer gender;
private String mobile;
private String name;
private String workType;
public String getAgencyId() {
return agencyId;
}
public void setAgencyId(String agencyId) {
this.agencyId = agencyId;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWorkType() {
return workType;
}
public void setWorkType(String workType) {
this.workType = workType;
}
}
public static class InitCustomerAgency {
private String agencyId;
private String organizationName;
private String level;
private String areaCode;
private String province;
private String city;
private String district;
public String getAgencyId() {
return agencyId;
}
public void setAgencyId(String agencyId) {
this.agencyId = agencyId;
}
public String getOrganizationName() {
return organizationName;
}
public void setOrganizationName(String organizationName) {
this.organizationName = organizationName;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getAreaCode() {
return areaCode;
}
public void setAreaCode(String areaCode) {
this.areaCode = areaCode;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public InitCustomerAgency getAgency() {
return agency;
}
public void setAgency(InitCustomerAgency agency) {
this.agency = agency;
}
public InitCustomerStaff getStaff() {
return staff;
}
public void setStaff(InitCustomerStaff staff) {
this.staff = staff;
}
}

1
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java

@ -20,6 +20,7 @@ public enum EpmetErrorCode {
ERR10006(10006, "登录超时,请重新登录"), ERR10006(10006, "登录超时,请重新登录"),
ERR10007(10007, "当前帐号已在别处登录"), ERR10007(10007, "当前帐号已在别处登录"),
ERR10019(10019, "验证码不正确"), ERR10019(10019, "验证码不正确"),
SYSTEM_MQ_MSG_SEND_FAIL(10020, "MQ消息发送失败"),
ERR401(401, "未授权"), ERR401(401, "未授权"),
INTERNAL_VALIDATE_ERROR(7000, "内部数据校验异常"), INTERNAL_VALIDATE_ERROR(7000, "内部数据校验异常"),
SERVER_ERROR(8000, "服务器开小差了..."), SERVER_ERROR(8000, "服务器开小差了..."),

1
epmet-commons/pom.xml

@ -23,6 +23,7 @@
<module>epmet-commons-tools-wx-mp</module> <module>epmet-commons-tools-wx-mp</module>
<module>epmet-commons-service-call</module> <module>epmet-commons-service-call</module>
<module>epmet-commons-extapp-auth</module> <module>epmet-commons-extapp-auth</module>
<module>epmet-commons-rocketmq</module>
</modules> </modules>
</project> </project>

7
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageSendApproach.java

@ -0,0 +1,7 @@
package com.epmet.constant;
public interface SystemMessageSendApproach {
String MQ = "mq";
}

13
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java

@ -0,0 +1,13 @@
package com.epmet.constant;
/**
* 系统消息类型
*/
public interface SystemMessageType {
/**
* 初始化客户
*/
String INIT_CUSTOMER = "init_customer";
}

15
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/form/SystemMsgFormDTO.java

@ -0,0 +1,15 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class SystemMsgFormDTO {
@NotNull(message = "消息类型不能为空")
private String messageType;
@NotNull(message = "消息内容不能为空")
private Object content;
}

10
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/feign/EpmetMessageOpenFeignClient.java

@ -4,6 +4,7 @@ import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.SysSmsDTO; import com.epmet.dto.SysSmsDTO;
import com.epmet.dto.form.SendVerificationCodeFormDTO; import com.epmet.dto.form.SendVerificationCodeFormDTO;
import com.epmet.dto.form.SystemMsgFormDTO;
import com.epmet.dto.form.UserMessageFormDTO; import com.epmet.dto.form.UserMessageFormDTO;
import com.epmet.dto.form.WxSubscribeMessageFormDTO; import com.epmet.dto.form.WxSubscribeMessageFormDTO;
import com.epmet.dto.result.SendVerificationCodeResultDTO; import com.epmet.dto.result.SendVerificationCodeResultDTO;
@ -77,4 +78,13 @@ public interface EpmetMessageOpenFeignClient {
**/ **/
@PostMapping(value = "message/wxmpmessage/sendwxsubscribemessage", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @PostMapping(value = "message/wxmpmessage/sendwxsubscribemessage", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
Result sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList); Result sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList);
/**
* @Description 通过mq发送系统消息
* @return
* @author wxz
* @date 2021.01.06 15:16
*/
@PostMapping("/message/system/send-by-mq")
Result sendSystemMsgByMQ(@RequestBody SystemMsgFormDTO form);
} }

6
epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/feign/fallback/EpmetMessageOpenFeignClientFallback.java

@ -5,6 +5,7 @@ import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.SysSmsDTO; import com.epmet.dto.SysSmsDTO;
import com.epmet.dto.form.SendVerificationCodeFormDTO; import com.epmet.dto.form.SendVerificationCodeFormDTO;
import com.epmet.dto.form.SystemMsgFormDTO;
import com.epmet.dto.form.UserMessageFormDTO; import com.epmet.dto.form.UserMessageFormDTO;
import com.epmet.dto.form.WxSubscribeMessageFormDTO; import com.epmet.dto.form.WxSubscribeMessageFormDTO;
import com.epmet.dto.result.SendVerificationCodeResultDTO; import com.epmet.dto.result.SendVerificationCodeResultDTO;
@ -51,4 +52,9 @@ public class EpmetMessageOpenFeignClientFallback implements EpmetMessageOpenFeig
public Result sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList) { public Result sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_MESSAGE_SERVER, "sendWxSubscribeMessage", msgList); return ModuleUtils.feignConError(ServiceConstant.EPMET_MESSAGE_SERVER, "sendWxSubscribeMessage", msgList);
} }
@Override
public Result sendSystemMsgByMQ(SystemMsgFormDTO form) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_MESSAGE_SERVER, "sendSystemMsgByMQ", form);
}
} }

7
epmet-module/epmet-message/epmet-message-server/pom.xml

@ -112,6 +112,13 @@
<version>2.0.0</version> <version>2.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--rocketmq-->
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

27
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/SystemMessageController.java

@ -0,0 +1,27 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.form.SystemMsgFormDTO;
import com.epmet.service.SystemMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("system")
public class SystemMessageController {
@Autowired
private SystemMessageService systemMessageService;
@PostMapping("send-by-mq")
public Result sendSystemMsgByMQ(@RequestBody SystemMsgFormDTO form) {
ValidatorUtils.validateEntity(form);
systemMessageService.sendMQMessage(form.getMessageType(), form.getContent());
return new Result();
}
}

33
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/SystemMessageDao.java

@ -0,0 +1,33 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.SystemMessageEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 系统消息表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-01-06
*/
@Mapper
public interface SystemMessageDao extends BaseDao<SystemMessageEntity> {
}

57
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/entity/SystemMessageEntity.java

@ -0,0 +1,57 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.omg.CORBA.StringHolder;
import java.util.Date;
/**
* 系统消息表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-01-06
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("system_message")
public class SystemMessageEntity extends BaseEpmetEntity {
private static final long serialVersionUID = 1L;
/**
* 消息类型
*/
private String msgType;
/**
* 发送途径
*/
private String sendApproach;
/**
* 消息内容
*/
private String content;
}

7
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/SystemMessageService.java

@ -0,0 +1,7 @@
package com.epmet.service;
public interface SystemMessageService {
void sendMQMessage(String messageType, Object content);
}

70
epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java

@ -0,0 +1,70 @@
package com.epmet.service.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.rocketmq.constants.TopicConstants;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.constant.SystemMessageSendApproach;
import com.epmet.constant.SystemMessageType;
import com.epmet.dao.SystemMessageDao;
import com.epmet.entity.SystemMessageEntity;
import com.epmet.service.SystemMessageService;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SystemMessageServiceImpl implements SystemMessageService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private SystemMessageDao systemMessageDao;
@Autowired
private RocketMQTemplate rocketMQTemplate;
@Transactional(rollbackFor = Exception.class)
@Override
public void sendMQMessage(String messageType, Object content) {
String contentStr = JSON.toJSONString(content);
//存储消息到表
SystemMessageEntity systemMessageEntity = new SystemMessageEntity();
systemMessageEntity.setMsgType(messageType);
systemMessageEntity.setSendApproach(SystemMessageSendApproach.MQ);
systemMessageEntity.setContent(contentStr);
systemMessageDao.insert(systemMessageEntity);
//发送mq消息
try {
Message meMessage = new Message(getTopicByMsgType(messageType), contentStr.getBytes(RemotingHelper.DEFAULT_CHARSET));
rocketMQTemplate.getProducer().send(meMessage);
} catch (Exception e) {
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e);
logger.error("发送系统消息失败,堆栈信息:{}", errorStackTrace);
throw new RenException(EpmetErrorCode.SYSTEM_MQ_MSG_SEND_FAIL.getCode());
}
}
/**
* @Description 根据消息类型获取topic
* @return
* @author wxz
* @date 2021.01.06 13:42
*/
private String getTopicByMsgType(String msgType) {
String topic = null;
switch (msgType) {
case SystemMessageType.INIT_CUSTOMER:
topic = TopicConstants.INIT_CUSTOMER;
break;
}
return topic;
}
}

7
epmet-module/epmet-message/epmet-message-server/src/main/resources/bootstrap.yml

@ -131,4 +131,9 @@ thread:
dingTalk: dingTalk:
robot: robot:
webHook: @dingTalk.robot.webHook@ webHook: @dingTalk.robot.webHook@
secret: @dingTalk.robot.secret@ secret: @dingTalk.robot.secret@
rocketmq:
name-server: 192.168.1.130:9876;192.168.1.132:9876
producer:
group: epmet_message

18
epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/SystemMessageDao.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.epmet.dao.SystemMessageDao">
<resultMap type="com.epmet.entity.SystemMessageEntity" id="systemMessageMap">
<result property="id" column="ID"/>
<result property="content" column="CONTENT"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
</mapper>

6
epmet-module/gov-org/gov-org-server/pom.xml

@ -95,6 +95,12 @@
<version>2.0.0</version> <version>2.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--rocketmq-->
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

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

@ -0,0 +1,76 @@
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.constant.UserWorkType;
import com.epmet.dto.CustomerAgencyDTO;
import com.epmet.dto.form.AddAgencyAndStaffFormDTO;
import com.epmet.dto.form.AdminStaffFromDTO;
import com.epmet.service.AgencyService;
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_ORG_GROUP,
messageModel = MessageModel.CLUSTERING,
selectorExpression = "*")
@Component
public class InitCustomerOrgListener implements RocketMQListener<MessageExt> {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private AgencyService agencyService;
@Override
public void onMessage(MessageExt messageExt) {
String msg = new String(messageExt.getBody());
logger.info("初始化客户-初始化组织信息-收到消息内容:{}", msg);
InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class);
agencyService.saveRootAgency(constructRootAndAgencyDTO(msgObj));
}
/**
* @Description 构造dto
* @return
* @author wxz
* @date 2021.01.06 15:03
*/
private AddAgencyAndStaffFormDTO constructRootAndAgencyDTO(InitCustomerMQMsg msgObj) {
AddAgencyAndStaffFormDTO agencyAndStaff = new AddAgencyAndStaffFormDTO();
//客户组织信息
CustomerAgencyDTO agencyDTO = new CustomerAgencyDTO();
agencyDTO.setId(msgObj.getAgency().getAgencyId());
agencyDTO.setCustomerId(msgObj.getCustomerId());
agencyDTO.setOrganizationName(msgObj.getAgency().getOrganizationName());
agencyDTO.setLevel(msgObj.getAgency().getLevel());
agencyDTO.setAreaCode(msgObj.getAgency().getAreaCode());
agencyDTO.setProvince(msgObj.getAgency().getProvince());
agencyDTO.setCity(msgObj.getAgency().getCity());
agencyDTO.setDistrict(msgObj.getAgency().getDistrict());
agencyAndStaff.setAgencyDTO(agencyDTO);
//客户管理员信息
AdminStaffFromDTO staffSubmitFrom = new AdminStaffFromDTO();
staffSubmitFrom.setCustomerId(msgObj.getCustomerId());
staffSubmitFrom.setAgencyId(msgObj.getStaff().getAgencyId());
staffSubmitFrom.setGender(msgObj.getStaff().getGender());
staffSubmitFrom.setMobile(msgObj.getStaff().getMobile());
staffSubmitFrom.setName(msgObj.getStaff().getName());
staffSubmitFrom.setWorkType(UserWorkType.FULL_TIME);
agencyAndStaff.setStaffDTO(staffSubmitFrom);
return agencyAndStaff;
}
}

5
epmet-module/gov-org/gov-org-server/src/main/resources/bootstrap.yml

@ -135,4 +135,7 @@ pagehelper:
dingTalk: dingTalk:
robot: robot:
webHook: @dingTalk.robot.webHook@ webHook: @dingTalk.robot.webHook@
secret: @dingTalk.robot.secret@ secret: @dingTalk.robot.secret@
rocketmq:
name-server: 192.168.1.130:9876;192.168.1.132:9876

12
epmet-module/oper-crm/oper-crm-server/pom.xml

@ -87,6 +87,18 @@
<version>2.0.0</version> <version>2.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-message-client</artifactId>
<version>2.0.0</version>
</dependency>
<!--rocketmq-->
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

124
epmet-module/oper-crm/oper-crm-server/src/main/java/com/epmet/service/impl/CustomerServiceImpl.java

@ -22,6 +22,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.rocketmq.messages.InitCustomerMQMsg;
import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetErrorCode;
@ -32,6 +33,7 @@ import com.epmet.commons.tools.utils.HttpClientManager;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.ModuleConstant; import com.epmet.constant.ModuleConstant;
import com.epmet.constant.RoleKeyConstants; import com.epmet.constant.RoleKeyConstants;
import com.epmet.constant.SystemMessageType;
import com.epmet.constant.UserWorkType; import com.epmet.constant.UserWorkType;
import com.epmet.dao.CustomerDao; import com.epmet.dao.CustomerDao;
import com.epmet.dto.*; import com.epmet.dto.*;
@ -80,6 +82,8 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerDao, CustomerEn
private CustomerDao customerDao; private CustomerDao customerDao;
@Autowired @Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Override @Override
public PageData<CustomerDTO> page(Map<String, Object> params) { public PageData<CustomerDTO> page(Map<String, Object> params) {
@ -468,48 +472,62 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerDao, CustomerEn
throw new RenException(EpmetErrorCode.OPER_ADD_CUSTOMER_ERROR.getCode()); throw new RenException(EpmetErrorCode.OPER_ADD_CUSTOMER_ERROR.getCode());
} }
//3.调用epmet-user服务,初始化客户对应的角色;调用access服务给角色分配权限信息 // *.发送初始化客户信息到mq,让监听者完成初始化操作
Result initResult = epmetUserFeignClient.initGovStaffRolesForCustomer(formDTO.getCustomerId()); InitCustomerMQMsg msgContent = new InitCustomerMQMsg();
if (!initResult.success()) { msgContent.setCustomerId(formDTO.getCustomerId());
throw new RenException("客户新增:调用user服务为客户初始化角色数据失败:".concat(initResult.toString())); msgContent.setAgency(constructAgencyInfo4CustomerInit(paAgency));
} msgContent.setStaff(constructStaffInfo4CustomerInit(paAgency.getId(), paUser));
//4.调用oper-customize服务,初始化客户定制化首页模板数据 SystemMsgFormDTO systemMsgFormDTO = new SystemMsgFormDTO();
CustomerHomeDTO initHomeForm = new CustomerHomeDTO(); systemMsgFormDTO.setMessageType(SystemMessageType.INIT_CUSTOMER);
initHomeForm.setCustomerId(formDTO.getCustomerId()); systemMsgFormDTO.setContent(msgContent);
Result initHomeResult = operCustomizeFeignClient.init(initHomeForm); Result sendMsgResult = epmetMessageOpenFeignClient.sendSystemMsgByMQ(systemMsgFormDTO);
if (!initHomeResult.success()) { if (! sendMsgResult.success()) {
throw new RenException("初始化客户首页数据失败:".concat(initHomeResult.getInternalMsg())); throw new RenException("发送(初始化客户信息)系统消息到message服务失败:{}", sendMsgResult.getInternalMsg());
} }
//5.调用gov-org服务,初始化客户根级组织信息、客户管理员信息 ////3.调用epmet-user服务,初始化客户对应的角色;调用access服务给角色分配权限信息
AddAgencyAndStaffFormDTO agencyAndStaff = new AddAgencyAndStaffFormDTO(); //Result initResult = epmetUserFeignClient.initGovStaffRolesForCustomer(formDTO.getCustomerId());
//客户组织信息 //if (!initResult.success()) {
CustomerAgencyDTO agencyDTO = new CustomerAgencyDTO(); // throw new RenException("客户新增:调用user服务为客户初始化角色数据失败:".concat(initResult.toString()));
agencyDTO.setId(paAgency.getId()); //}
agencyDTO.setCustomerId(formDTO.getCustomerId()); //
agencyDTO.setOrganizationName(paAgency.getAgencyName()); ////4.调用oper-customize服务,初始化客户定制化首页模板数据
agencyDTO.setLevel(paAgency.getLevel()); //CustomerHomeDTO initHomeForm = new CustomerHomeDTO();
agencyDTO.setAreaCode(paAgency.getAreaCode()); //initHomeForm.setCustomerId(formDTO.getCustomerId());
agencyDTO.setProvince(paAgency.getProvince()); //Result initHomeResult = operCustomizeFeignClient.init(initHomeForm);
agencyDTO.setCity(paAgency.getCity()); //if (!initHomeResult.success()) {
agencyDTO.setDistrict(paAgency.getDistrict()); // throw new RenException("初始化客户首页数据失败:".concat(initHomeResult.getInternalMsg()));
agencyAndStaff.setAgencyDTO(agencyDTO); //}
//
//客户管理员信息 ////5.调用gov-org服务,初始化客户根级组织信息、客户管理员信息
AdminStaffFromDTO staffSubmitFrom = new AdminStaffFromDTO(); //AddAgencyAndStaffFormDTO agencyAndStaff = new AddAgencyAndStaffFormDTO();
staffSubmitFrom.setCustomerId(formDTO.getCustomerId()); ////客户组织信息
staffSubmitFrom.setAgencyId(paAgency.getId()); //CustomerAgencyDTO agencyDTO = new CustomerAgencyDTO();
staffSubmitFrom.setGender(Integer.parseInt(paUser.getGender())); //agencyDTO.setId(paAgency.getId());
staffSubmitFrom.setMobile(paUser.getPhone()); //agencyDTO.setCustomerId(formDTO.getCustomerId());
staffSubmitFrom.setName(paUser.getRealName()); //agencyDTO.setOrganizationName(paAgency.getAgencyName());
staffSubmitFrom.setWorkType(UserWorkType.FULL_TIME); //agencyDTO.setLevel(paAgency.getLevel());
agencyAndStaff.setStaffDTO(staffSubmitFrom); //agencyDTO.setAreaCode(paAgency.getAreaCode());
//agencyDTO.setProvince(paAgency.getProvince());
Result agencyResult = govOrgOpenFeignClient.saveRootAgency(agencyAndStaff); //agencyDTO.setCity(paAgency.getCity());
if (!agencyResult.success()) { //agencyDTO.setDistrict(paAgency.getDistrict());
throw new RenException(agencyResult.getCode(), agencyResult.getInternalMsg()); //agencyAndStaff.setAgencyDTO(agencyDTO);
} //
////客户管理员信息
//AdminStaffFromDTO staffSubmitFrom = new AdminStaffFromDTO();
//staffSubmitFrom.setCustomerId(formDTO.getCustomerId());
//staffSubmitFrom.setAgencyId(paAgency.getId());
//staffSubmitFrom.setGender(Integer.parseInt(paUser.getGender()));
//staffSubmitFrom.setMobile(paUser.getPhone());
//staffSubmitFrom.setName(paUser.getRealName());
//staffSubmitFrom.setWorkType(UserWorkType.FULL_TIME);
//agencyAndStaff.setStaffDTO(staffSubmitFrom);
//
//Result agencyResult = govOrgOpenFeignClient.saveRootAgency(agencyAndStaff);
//if (!agencyResult.success()) {
// throw new RenException(agencyResult.getCode(), agencyResult.getInternalMsg());
//}
//6.更新第三方数据库中客户数据状态为已初始化 //6.更新第三方数据库中客户数据状态为已初始化
String customerUrl = "https://epmet-cloud.elinkservice.cn/api/third/pacustomer/updatecustomer/" + formDTO.getCustomerId(); String customerUrl = "https://epmet-cloud.elinkservice.cn/api/third/pacustomer/updatecustomer/" + formDTO.getCustomerId();
@ -531,6 +549,28 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerDao, CustomerEn
} }
private InitCustomerMQMsg.InitCustomerStaff constructStaffInfo4CustomerInit(String agencyId, PaUserDTO paUser) {
InitCustomerMQMsg.InitCustomerStaff staff = new InitCustomerMQMsg.InitCustomerStaff();
staff.setAgencyId(agencyId);
staff.setGender(Integer.parseInt(paUser.getGender()));
staff.setMobile(paUser.getPhone());
staff.setName(paUser.getRealName());
staff.setWorkType(UserWorkType.FULL_TIME);
return staff;
}
private InitCustomerMQMsg.InitCustomerAgency constructAgencyInfo4CustomerInit(PaCustomerAgencyDTO paAgency) {
InitCustomerMQMsg.InitCustomerAgency initCustomerAgency = new InitCustomerMQMsg.InitCustomerAgency();
initCustomerAgency.setAgencyId(paAgency.getId());
initCustomerAgency.setOrganizationName(paAgency.getAgencyName());
initCustomerAgency.setLevel(paAgency.getLevel());
initCustomerAgency.setAreaCode(paAgency.getAreaCode());
initCustomerAgency.setProvince(paAgency.getProvince());
initCustomerAgency.setCity(paAgency.getCity());
initCustomerAgency.setDistrict(paAgency.getDistrict());
return initCustomerAgency;
}
@Override @Override
public List<CustomerDTO> getAllList() { public List<CustomerDTO> getAllList() {
List<CustomerEntity> list = baseDao.getAllList(); List<CustomerEntity> list = baseDao.getAllList();

7
epmet-module/oper-customize/oper-customize-server/pom.xml

@ -70,6 +70,13 @@
<version>2.0.0</version> <version>2.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--rocketmq-->
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

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

@ -0,0 +1,43 @@
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.dto.CustomerHomeDTO;
import com.epmet.service.CustomerHomeService;
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_CUSTOMIZE_GROUP,
messageModel = MessageModel.CLUSTERING,
selectorExpression = "*")
@Component
public class InitCustomerCustomizeListener implements RocketMQListener<MessageExt> {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private CustomerHomeService customerHomeService;
@Override
public void onMessage(MessageExt messageExt) {
String msg = new String(messageExt.getBody());
logger.info("初始化客户-初始化客户自定义信息-收到消息内容:{}", msg);
InitCustomerMQMsg msgObj = JSON.parseObject(msg, InitCustomerMQMsg.class);
CustomerHomeDTO customerHomeDTO = new CustomerHomeDTO();
customerHomeDTO.setCustomerId(msgObj.getCustomerId());
customerHomeService.init(customerHomeDTO);
}
}

5
epmet-module/oper-customize/oper-customize-server/src/main/resources/bootstrap.yml

@ -122,4 +122,7 @@ pagehelper:
dingTalk: dingTalk:
robot: robot:
webHook: @dingTalk.robot.webHook@ webHook: @dingTalk.robot.webHook@
secret: @dingTalk.robot.secret@ secret: @dingTalk.robot.secret@
rocketmq:
name-server: 192.168.1.130:9876;192.168.1.132:9876

6
epmet-user/epmet-user-server/pom.xml

@ -100,6 +100,12 @@
<version>2.0.0</version> <version>2.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!--rocketmq-->
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-rocketmq</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

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

@ -0,0 +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());
}
}

5
epmet-user/epmet-user-server/src/main/resources/bootstrap.yml

@ -144,4 +144,7 @@ openapi:
dingTalk: dingTalk:
robot: robot:
webHook: @dingTalk.robot.webHook@ webHook: @dingTalk.robot.webHook@
secret: @dingTalk.robot.secret@ secret: @dingTalk.robot.secret@
rocketmq:
name-server: 192.168.1.130:9876;192.168.1.132:9876
Loading…
Cancel
Save