forked from luyan/epmet-cloud-lingshan
				
			
			
			
				Browse Source
			
			
			
			
				
		# Conflicts: # epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/feign/EpmetMessageOpenFeignClient.java # epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/feign/fallback/EpmetMessageOpenFeignClientFallback.java # epmet-module/epmet-message/epmet-message-server/pom.xmlmaster
				 40 changed files with 892 additions and 47 deletions
			
			
		@ -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> | 
				
			|||
@ -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"; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,5 @@ | 
				
			|||
package com.epmet.commons.rocketmq.constants; | 
				
			|||
 | 
				
			|||
public interface TopicConstants { | 
				
			|||
    String INIT_CUSTOMER = "init_customer_topic"; | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,7 @@ | 
				
			|||
package com.epmet.constant; | 
				
			|||
 | 
				
			|||
public interface SystemMessageSendApproach { | 
				
			|||
 | 
				
			|||
    String MQ = "mq"; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,13 @@ | 
				
			|||
package com.epmet.constant; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 系统消息类型 | 
				
			|||
 */ | 
				
			|||
public interface SystemMessageType { | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 初始化客户 | 
				
			|||
     */ | 
				
			|||
    String INIT_CUSTOMER = "init_customer"; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
} | 
				
			|||
@ -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(); | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -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> { | 
				
			|||
	 | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -0,0 +1,7 @@ | 
				
			|||
package com.epmet.service; | 
				
			|||
 | 
				
			|||
public interface SystemMessageService { | 
				
			|||
 | 
				
			|||
    void sendMQMessage(String messageType, Object content); | 
				
			|||
 | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,13 @@ | 
				
			|||
CREATE TABLE `system_message` ( | 
				
			|||
  `ID` varchar(64) NOT NULL COMMENT '主键', | 
				
			|||
  `MSG_TYPE` varchar(32) NOT NULL COMMENT '消息类型。init_customer:客户初始化', | 
				
			|||
  `SEND_APPROACH` varchar(32) NOT NULL COMMENT '消息发送途径', | 
				
			|||
  `CONTENT` varchar(1024) NOT NULL COMMENT '消息内容', | 
				
			|||
  `REVISION` int(11) DEFAULT NULL COMMENT '乐观锁', | 
				
			|||
  `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人(发布消息的人)', | 
				
			|||
  `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', | 
				
			|||
  `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', | 
				
			|||
  `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', | 
				
			|||
  `DEL_FLAG` varchar(1) NOT NULL COMMENT '删除标记 0:未删除,1:已删除', | 
				
			|||
  PRIMARY KEY (`ID`) USING BTREE | 
				
			|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='系统消息表' | 
				
			|||
@ -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> | 
				
			|||
@ -0,0 +1,87 @@ | 
				
			|||
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.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; | 
				
			|||
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); | 
				
			|||
        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; | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * @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; | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,54 @@ | 
				
			|||
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.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; | 
				
			|||
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()); | 
				
			|||
        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; | 
				
			|||
        } | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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());
 | 
				
			|||
//    }
 | 
				
			|||
//}
 | 
				
			|||
					Loading…
					
					
				
		Reference in new issue