企业初始化
This commit is contained in:
@@ -57,6 +57,16 @@
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.5.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.0.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.coolstore:coolstore-base:1.5.3" level="project" />
|
||||
<orderEntry type="module" module-name="coolstore-partner-dao" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.2" level="project" />
|
||||
@@ -67,14 +77,6 @@
|
||||
<orderEntry type="library" name="Maven: com.alibaba:druid-spring-boot-starter:1.1.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba:druid:1.1.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.2.6.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.0.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.4.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.5" level="project" />
|
||||
<orderEntry type="module" module-name="coolstore-partner-model" />
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-spring-boot-starter:2.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-spring-boot-autoconfigure:2.0.4" level="project" />
|
||||
@@ -99,5 +101,24 @@
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-spring-ui:2.0.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun.openservices:ons-client:1.8.8.3.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:tea-openapi:0.0.19" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:tea-util:0.2.12" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:credentials-java:0.2.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ini4j:ini4j:0.5.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jacoco:org.jacoco.agent:runtime:0.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:openapiutil:0.1.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bouncycastle:bcpkix-jdk15on:1.65" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.65" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:tea:1.2.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.14.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:ons20190214:1.0.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.aliyun:endpoint-util:0.0.6" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -33,6 +33,18 @@
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun.openservices</groupId>
|
||||
<artifactId>ons-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ons20190214</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.cool.store.http;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserDTO;
|
||||
import com.cool.store.dto.login.UserIdInfoDTO;
|
||||
import com.cool.store.utils.RestTemplateUtil;
|
||||
import com.coolstore.base.dto.ResultDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -26,18 +29,33 @@ public class ISVHttpRequest {
|
||||
private String getUserIdByCode;
|
||||
|
||||
|
||||
public JSONObject getUserIdByCode(String paramStr){
|
||||
String url = isvDomain + getUserIdByCode + paramStr;
|
||||
ResponseEntity<JSONObject> responseEntity = null;
|
||||
public UserIdInfoDTO getUserIdByCode(String paramStr){
|
||||
String url = isvDomain + "/isv/user/getUserIdByCode" + paramStr;
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.loadGet(url, JSONObject.class);
|
||||
responseEntity = RestTemplateUtil.loadGet(url, ResultDTO.class);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), UserIdInfoDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
}
|
||||
if(Objects.isNull(responseEntity)){
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public EnterpriseUserDTO getUserDetailByUserId(String corpId, String userId, String appType){
|
||||
String url = isvDomain + "/isv/user/getUserDetail";
|
||||
ResponseEntity<ResultDTO> responseEntity = null;
|
||||
try {
|
||||
responseEntity = RestTemplateUtil.loadGet(url, ResultDTO.class);
|
||||
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
|
||||
if(Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()){
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), EnterpriseUserDTO.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("调用isv出错{}", e);
|
||||
}
|
||||
return responseEntity.getBody();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.cool.store.mq;
|
||||
|
||||
import com.aliyun.openservices.ons.api.SendResult;
|
||||
import com.coolstore.base.enums.RocketMqTagEnum;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: OrderMessageService
|
||||
* @Description: 顺序消息生产者
|
||||
* @date 2021-12-22 17:37
|
||||
*/
|
||||
public interface OrderMessageService {
|
||||
|
||||
/**
|
||||
* 发送顺序消息
|
||||
* @param message
|
||||
* @param tag
|
||||
* @param shardingKey
|
||||
* @return
|
||||
*/
|
||||
SendResult send(String message, RocketMqTagEnum tag, final String shardingKey);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.cool.store.mq;
|
||||
|
||||
import com.aliyun.openservices.ons.api.bean.OrderProducerBean;
|
||||
import com.aliyun.openservices.ons.api.bean.ProducerBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: ProducerClient
|
||||
* @Description: 普通消息client
|
||||
* @date 2021-12-21 11:33
|
||||
*/
|
||||
@Configuration
|
||||
public class ProducerClient {
|
||||
|
||||
@Autowired
|
||||
private RocketMqConfig rocketMqConfig;
|
||||
|
||||
/**
|
||||
* 普通消息
|
||||
* @return
|
||||
*/
|
||||
@Primary
|
||||
@Bean(initMethod = "start", destroyMethod = "shutdown")
|
||||
public ProducerBean producerBean() {
|
||||
ProducerBean producer = new ProducerBean();
|
||||
producer.setProperties(rocketMqConfig.getMqProperties());
|
||||
return producer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分区顺序消息
|
||||
* @return
|
||||
*/
|
||||
@Bean(initMethod = "start", destroyMethod = "shutdown")
|
||||
public OrderProducerBean orderProducerBean() {
|
||||
OrderProducerBean producer = new OrderProducerBean();
|
||||
producer.setProperties(rocketMqConfig.getMqProperties());
|
||||
return producer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.cool.store.mq;
|
||||
|
||||
import com.aliyun.openservices.ons.api.PropertyKeyConst;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: RocketMqConfig
|
||||
* @Description: 该服务的rocketmq的配置 以及生产者的topic
|
||||
* @date 2021-12-21 11:33
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "rocketmq")
|
||||
public class RocketMqConfig {
|
||||
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String nameSrvAdder;
|
||||
/**
|
||||
* 普通消息的topic
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 分区顺序消息topic
|
||||
*/
|
||||
private String orderTopic;
|
||||
|
||||
public Properties getMqProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(PropertyKeyConst.AccessKey, this.accessKey);
|
||||
properties.setProperty(PropertyKeyConst.SecretKey, this.secretKey);
|
||||
properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, this.nameSrvAdder);
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getNameSrvAdder() {
|
||||
return nameSrvAdder;
|
||||
}
|
||||
|
||||
public void setNameSrvAdder(String nameSrvAdder) {
|
||||
this.nameSrvAdder = nameSrvAdder;
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
public void setTopic(String topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
public String getOrderTopic() {
|
||||
return orderTopic;
|
||||
}
|
||||
|
||||
public void setOrderTopic(String orderTopic) {
|
||||
this.orderTopic = orderTopic;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.cool.store.mq;
|
||||
|
||||
import com.aliyun.openservices.ons.api.SendCallback;
|
||||
import com.aliyun.openservices.ons.api.SendResult;
|
||||
import com.coolstore.base.enums.RocketMqTagEnum;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: MessageProducerService
|
||||
* @Description: rocketmq 消息生产者
|
||||
* @date 2021-12-22 16:12
|
||||
*/
|
||||
public interface SimpleMessageService {
|
||||
|
||||
/**
|
||||
* 同步发送
|
||||
* @param message 消息
|
||||
* @param tag tag
|
||||
* @return
|
||||
*/
|
||||
SendResult send(String message, RocketMqTagEnum tag);
|
||||
|
||||
/**
|
||||
* 单向发送
|
||||
* @param message 消息
|
||||
* @param tag tag
|
||||
*/
|
||||
void sendOneway(String message, RocketMqTagEnum tag);
|
||||
|
||||
/**
|
||||
* 异步发送
|
||||
* @param message 消息
|
||||
* @param tag tag
|
||||
* @param sendCallback 回调
|
||||
*/
|
||||
void sendAsync(String message, RocketMqTagEnum tag, SendCallback sendCallback);
|
||||
|
||||
/**
|
||||
* 同步发送(延时)
|
||||
* @param message
|
||||
* @param tag
|
||||
* @param startDeliverTime
|
||||
* @return
|
||||
*/
|
||||
SendResult send(String message, RocketMqTagEnum tag, Long startDeliverTime);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.cool.store.mq.impl;
|
||||
|
||||
import com.aliyun.openservices.ons.api.Message;
|
||||
import com.aliyun.openservices.ons.api.SendResult;
|
||||
import com.aliyun.openservices.ons.api.bean.OrderProducerBean;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.mq.OrderMessageService;
|
||||
import com.cool.store.mq.RocketMqConfig;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import com.coolstore.base.enums.RocketMqTagEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: OrderMessageServiceImpl
|
||||
* @Description: 顺序消息生产实现
|
||||
* @date 2021-12-22 17:38
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OrderMessageServiceImpl implements OrderMessageService {
|
||||
|
||||
@Resource
|
||||
private RocketMqConfig rocketMqConfig;
|
||||
|
||||
@Resource
|
||||
private OrderProducerBean orderProducerBean;
|
||||
|
||||
@Override
|
||||
public SendResult send(String message, RocketMqTagEnum tag, String shardingKey) {
|
||||
if(StringUtils.isAnyBlank(message, shardingKey) || Objects.isNull(tag)){
|
||||
return new SendResult();
|
||||
}
|
||||
try {
|
||||
Message msg = new Message(rocketMqConfig.getOrderTopic(), tag.getTag(), message.getBytes("UTF-8"));
|
||||
Properties properties = new Properties();
|
||||
String requestId = MDC.get(CommonConstants.REQUEST_ID);
|
||||
if(StringUtils.isBlank(requestId)){
|
||||
requestId = UUIDUtils.get32UUID();
|
||||
}
|
||||
properties.setProperty(CommonConstants.REQUEST_ID, requestId);
|
||||
msg.setUserProperties(properties);
|
||||
SendResult send = orderProducerBean.send(msg, shardingKey);
|
||||
return send;
|
||||
} catch (Exception e) {
|
||||
log.error("send@@@@@@@@@ddd", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.cool.store.mq.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.openservices.ons.api.Message;
|
||||
import com.aliyun.openservices.ons.api.SendCallback;
|
||||
import com.aliyun.openservices.ons.api.SendResult;
|
||||
import com.aliyun.openservices.ons.api.bean.ProducerBean;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.mq.RocketMqConfig;
|
||||
import com.cool.store.mq.SimpleMessageService;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import com.coolstore.base.enums.RocketMqTagEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: MessageProducerServiceImpl
|
||||
* @Description: 消息生产者实现
|
||||
* @date 2021-12-22 16:12
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SimpleMessageServiceImpl implements SimpleMessageService {
|
||||
|
||||
@Resource
|
||||
private RocketMqConfig rocketMqConfig;
|
||||
|
||||
@Resource
|
||||
private ProducerBean producer;
|
||||
|
||||
@Override
|
||||
public SendResult send(String message, RocketMqTagEnum tag) {
|
||||
if(StringUtils.isBlank(message) || Objects.isNull(tag)){
|
||||
return new SendResult();
|
||||
}
|
||||
try {
|
||||
Message msg = new Message(rocketMqConfig.getTopic(), tag.getTag(), message.getBytes("UTF-8"));
|
||||
Properties properties = new Properties();
|
||||
String requestId = MDC.get(CommonConstants.REQUEST_ID);
|
||||
if(StringUtils.isBlank(requestId)){
|
||||
requestId = UUIDUtils.get32UUID();
|
||||
}
|
||||
properties.setProperty(CommonConstants.REQUEST_ID, requestId);
|
||||
msg.setUserProperties(properties);
|
||||
SendResult send = producer.send(msg);
|
||||
log.info("消息发送send response:{}", JSONObject.toJSONString(send));
|
||||
return send;
|
||||
} catch (Exception e) {
|
||||
log.error("send#######", e);
|
||||
}
|
||||
return new SendResult();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOneway(String message, RocketMqTagEnum tag) {
|
||||
if(StringUtils.isBlank(message) || Objects.isNull(tag)){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Message msg = new Message(rocketMqConfig.getTopic(), tag.getTag(), message.getBytes("UTF-8"));
|
||||
Properties properties = new Properties();
|
||||
String requestId = MDC.get(CommonConstants.REQUEST_ID);
|
||||
if(StringUtils.isBlank(requestId)){
|
||||
requestId = UUIDUtils.get32UUID();
|
||||
}
|
||||
properties.setProperty(CommonConstants.REQUEST_ID, requestId);
|
||||
msg.setUserProperties(properties);
|
||||
producer.sendOneway(msg);
|
||||
} catch (Exception e) {
|
||||
log.error("send@@@@@@", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAsync(String message, RocketMqTagEnum tag, SendCallback sendCallback) {
|
||||
if(StringUtils.isBlank(message) || Objects.isNull(tag)){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Message msg = new Message(rocketMqConfig.getTopic(), tag.getTag(), message.getBytes("UTF-8"));
|
||||
Properties properties = new Properties();
|
||||
String requestId = MDC.get(CommonConstants.REQUEST_ID);
|
||||
if(StringUtils.isBlank(requestId)){
|
||||
requestId = UUIDUtils.get32UUID();
|
||||
}
|
||||
properties.setProperty(CommonConstants.REQUEST_ID, requestId);
|
||||
msg.setUserProperties(properties);
|
||||
producer.sendAsync(msg, sendCallback);
|
||||
} catch (Exception e) {
|
||||
log.error("sendAsync@@@@@@", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendResult send(String message, RocketMqTagEnum tag, Long startDeliverTime) {
|
||||
if(StringUtils.isBlank(message) || Objects.isNull(tag)){
|
||||
return new SendResult();
|
||||
}
|
||||
try {
|
||||
Message msg = new Message(rocketMqConfig.getTopic(), tag.getTag(), message.getBytes("UTF-8"));
|
||||
if(Objects.nonNull(startDeliverTime)) {
|
||||
log.info("{} startDeliverTime:{}", tag.getTag(),new Date(startDeliverTime));
|
||||
msg.setStartDeliverTime(startDeliverTime);
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
String requestId = MDC.get(CommonConstants.REQUEST_ID);
|
||||
if(StringUtils.isBlank(requestId)){
|
||||
requestId = UUIDUtils.get32UUID();
|
||||
}
|
||||
properties.setProperty(CommonConstants.REQUEST_ID, requestId);
|
||||
msg.setUserProperties(properties);
|
||||
SendResult send = producer.send(msg);
|
||||
log.info("发送消息:data:{}", JSONObject.toJSONString(send));
|
||||
return send;
|
||||
} catch (Exception e) {
|
||||
log.error("send@@@@@@@@@", e);
|
||||
}
|
||||
return new SendResult();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.cool.store.mq.util;
|
||||
|
||||
import com.aliyun.ons20190214.*;
|
||||
import com.aliyun.ons20190214.models.*;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.coolstore.base.enums.RocketMqGroupEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author chenyupeng
|
||||
* @since 2022/1/5
|
||||
*/
|
||||
@Slf4j
|
||||
public class RocketMqUtil {
|
||||
|
||||
private static final String INSTANCE_ID = "MQ_INST_1947409023213164_BX3sLZnA";
|
||||
|
||||
/**
|
||||
* 本地
|
||||
*/
|
||||
private static final String LOCAL_INSTANCE_ID = "MQ_INST_1255228665351616_BX3wfyPO";
|
||||
|
||||
private static final String INSTANCE_ID_ONLINE_HD_PRE = "MQ_INST_1947409023213164_BX5N7rwl";
|
||||
private static final String ACCESS_KEY = "LTAI5t5ouXZuFgxJMbQea3b2";
|
||||
private static final String ACCESS_SECRET = "yuomDstRjSdihtN5zo8viDbWu8Z0ig";
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param accessKeyId
|
||||
* @param accessKeySecret
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
Config config = new Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = "ons.cn-hangzhou.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static Client createLocalClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
Config config = new Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = "ons.mq-internet-access.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增测试、开发环境的group
|
||||
* @author chenyupeng
|
||||
* @date 2022/1/13
|
||||
* @param profiles 环境后缀,逗号分隔 例如: dev,dev2
|
||||
* @return void
|
||||
*/
|
||||
public static void initGroup(String profiles) throws Exception {
|
||||
Client client = RocketMqUtil.createClient(ACCESS_KEY, ACCESS_SECRET);
|
||||
List<String> profileList = Arrays.asList(profiles.split(CommonConstants.COMMA));
|
||||
if(CollectionUtils.isEmpty(profileList)){
|
||||
return;
|
||||
}
|
||||
|
||||
OnsGroupListRequest onsGroupListRequest = new OnsGroupListRequest();
|
||||
onsGroupListRequest.setInstanceId(INSTANCE_ID);
|
||||
OnsGroupListResponse onsGroupListResponse = client.onsGroupList(onsGroupListRequest);
|
||||
List<OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo> subscribeInfoDo = onsGroupListResponse.getBody().getData().getSubscribeInfoDo();
|
||||
Map<String, OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo> collect = ListUtils.emptyIfNull(subscribeInfoDo).stream().
|
||||
collect(Collectors.toMap(OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo::getGroupId, data -> data, (a, b) -> a));
|
||||
|
||||
for (String profile : profileList) {
|
||||
for (RocketMqGroupEnum groupEnum : RocketMqGroupEnum.values()) {
|
||||
String groupId = groupEnum.getDefaultGroup() + "_" + profile;
|
||||
//已经创建就继续
|
||||
if(collect.get(groupId) != null){
|
||||
continue;
|
||||
}
|
||||
OnsGroupCreateRequest onsGroupCreateRequest = new OnsGroupCreateRequest();
|
||||
onsGroupCreateRequest.setGroupId(groupId);
|
||||
onsGroupCreateRequest.setInstanceId(INSTANCE_ID);
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
try {
|
||||
client.onsGroupCreate(onsGroupCreateRequest);
|
||||
}catch (Exception e){
|
||||
log.error("initGroupAndTag fail",e);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void initLocalGroup(String profiles) throws Exception {
|
||||
Client client = RocketMqUtil.createLocalClient("LTAI5tPWCTeCyngfYLqoSGWk", "jkzIXlvNF17ne5TPPEFP1sQhcfg4Je");
|
||||
List<String> profileList = Arrays.asList(profiles.split(CommonConstants.COMMA));
|
||||
if(CollectionUtils.isEmpty(profileList)){
|
||||
return;
|
||||
}
|
||||
|
||||
OnsGroupListRequest onsGroupListRequest = new OnsGroupListRequest();
|
||||
onsGroupListRequest.setInstanceId(LOCAL_INSTANCE_ID);
|
||||
OnsGroupListResponse onsGroupListResponse = client.onsGroupList(onsGroupListRequest);
|
||||
List<OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo> subscribeInfoDo = onsGroupListResponse.getBody().getData().getSubscribeInfoDo();
|
||||
Map<String, OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo> collect = ListUtils.emptyIfNull(subscribeInfoDo).stream().
|
||||
collect(Collectors.toMap(OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo::getGroupId, data -> data, (a, b) -> a));
|
||||
|
||||
for (String profile : profileList) {
|
||||
for (RocketMqGroupEnum groupEnum : RocketMqGroupEnum.values()) {
|
||||
String groupId = groupEnum.getDefaultGroup() + "_" + profile;
|
||||
//已经创建就继续
|
||||
if(collect.get(groupId) != null){
|
||||
continue;
|
||||
}
|
||||
OnsGroupCreateRequest onsGroupCreateRequest = new OnsGroupCreateRequest();
|
||||
onsGroupCreateRequest.setGroupId(groupId);
|
||||
onsGroupCreateRequest.setInstanceId(LOCAL_INSTANCE_ID);
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
try {
|
||||
client.onsGroupCreate(onsGroupCreateRequest);
|
||||
}catch (Exception e){
|
||||
log.error("initGroupAndTag fail",e);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增线上、灰度、预发环境的group
|
||||
* @author chenyupeng
|
||||
* @date 2022/1/13
|
||||
* @param profiles 环境后缀,逗号分隔 例如: online,hd,pre
|
||||
* @return void
|
||||
*/
|
||||
public static void initOnlineAndHdAndPreGroup(String profiles) throws Exception {
|
||||
Client client = RocketMqUtil.createClient(ACCESS_KEY, ACCESS_SECRET);
|
||||
List<String> profileList = Arrays.asList(profiles.split(CommonConstants.COMMA));
|
||||
if(CollectionUtils.isEmpty(profileList)){
|
||||
return;
|
||||
}
|
||||
|
||||
OnsGroupListRequest onsGroupListRequest = new OnsGroupListRequest();
|
||||
onsGroupListRequest.setInstanceId(INSTANCE_ID_ONLINE_HD_PRE);
|
||||
OnsGroupListResponse onsGroupListResponse = client.onsGroupList(onsGroupListRequest);
|
||||
List<OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo> subscribeInfoDo = onsGroupListResponse.getBody().getData().getSubscribeInfoDo();
|
||||
Map<String, OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo> collect = ListUtils.emptyIfNull(subscribeInfoDo).stream().
|
||||
collect(Collectors.toMap(OnsGroupListResponseBody.OnsGroupListResponseBodyDataSubscribeInfoDo::getGroupId, data -> data, (a, b) -> a));
|
||||
|
||||
for (String profile : profileList) {
|
||||
for (RocketMqGroupEnum groupEnum : RocketMqGroupEnum.values()) {
|
||||
String groupId = groupEnum.getDefaultGroup() + "_" + profile;
|
||||
//已经创建就继续
|
||||
if(collect.get(groupId) != null){
|
||||
continue;
|
||||
}
|
||||
OnsGroupCreateRequest onsGroupCreateRequest = new OnsGroupCreateRequest();
|
||||
onsGroupCreateRequest.setGroupId(groupId);
|
||||
onsGroupCreateRequest.setInstanceId(INSTANCE_ID_ONLINE_HD_PRE);
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
try {
|
||||
client.onsGroupCreate(onsGroupCreateRequest);
|
||||
}catch (Exception e){
|
||||
log.error("initGroupAndTag fail",e);
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除测试、开发环境的group
|
||||
* @author chenyupeng
|
||||
* @date 2022/1/13
|
||||
* @param groupId
|
||||
* @return void
|
||||
*/
|
||||
public static void deleteGroupById(String groupId) throws Exception {
|
||||
Client client = RocketMqUtil.createClient(ACCESS_KEY, ACCESS_SECRET);
|
||||
OnsGroupDeleteRequest request = new OnsGroupDeleteRequest();
|
||||
request.setGroupId(groupId);
|
||||
request.setInstanceId(INSTANCE_ID);
|
||||
client.onsGroupDelete(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.EnterpriseUserRoleDAO;
|
||||
import com.cool.store.dao.SysRoleDAO;
|
||||
import com.cool.store.dto.enterprise.EnterpriseInitDTO;
|
||||
import com.cool.store.dto.enterprise.EnterpriseOpenMsg;
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserDTO;
|
||||
import com.cool.store.dto.enterprise.EnterpriseUserRole;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.enums.RoleEnum;
|
||||
import com.cool.store.http.ISVHttpRequest;
|
||||
import com.cool.store.mq.SimpleMessageService;
|
||||
import com.cool.store.utils.DataSourceHelper;
|
||||
import com.cool.store.utils.ScriptUtil;
|
||||
import com.cool.store.utils.UUIDUtils;
|
||||
import com.coolstore.base.enums.RocketMqTagEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: EnterpriseInitService
|
||||
* @Description: 企业初始化
|
||||
* @date 2023-05-26 16:28
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EnterpriseInitServiceImpl {
|
||||
|
||||
@Resource
|
||||
protected ScriptUtil scriptUtil;
|
||||
@Resource
|
||||
private SysRoleDAO sysRoleDAO;
|
||||
@Resource
|
||||
private EnterpriseUserRoleDAO enterpriseUserRoleDAO;
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
private SimpleMessageService simpleMessageService;
|
||||
@Resource
|
||||
private ISVHttpRequest isvHttpRequest;
|
||||
|
||||
public void runEnterpriseScript(EnterpriseOpenMsg msg) {
|
||||
runEnterpriseScriptAndInitAuthUser(msg);
|
||||
//抛出开始数据同步消息
|
||||
EnterpriseInitDTO enterpriseInitDTO = new EnterpriseInitDTO();
|
||||
enterpriseInitDTO.setEid(msg.getEid());
|
||||
enterpriseInitDTO.setAppType(msg.getAppType());
|
||||
enterpriseInitDTO.setCorpId(msg.getCorpId());
|
||||
enterpriseInitDTO.setDbName(msg.getDbName());
|
||||
enterpriseInitDTO.setUserId(msg.getAuthUserId());
|
||||
log.info("send msg to enterprise_open_data_sync, eid:{}, appType:{}, corpId:{}, dbName:{}", msg.getEid(), msg.getAppType(), msg.getCorpId(), msg.getDbName(), msg.getAuthUserId());
|
||||
simpleMessageService.send(JSONObject.toJSONString(enterpriseInitDTO), RocketMqTagEnum.ENTERPRISE_OPEN_DATA_SYNC);
|
||||
}
|
||||
|
||||
public void runEnterpriseScriptAndInitAuthUser(EnterpriseOpenMsg msg) {
|
||||
DataSourceHelper.changeToSpecificDataSource(msg.getDbName());
|
||||
//执行脚本代码
|
||||
ClassPathResource rc = new ClassPathResource("script/enterpriseInit.sql");
|
||||
EncodedResource er = new EncodedResource(rc, "utf-8");
|
||||
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
||||
objectObjectHashMap.put("enterpriseId", msg.getEid());
|
||||
String userId = msg.getAuthUserId();
|
||||
if(StringUtils.isBlank(userId)){
|
||||
objectObjectHashMap.put("userId", CommonConstants.SYSTEM_USER_ID);
|
||||
} else {
|
||||
objectObjectHashMap.put("userId", userId);
|
||||
}
|
||||
String groupId = UUIDUtils.get32UUID();
|
||||
objectObjectHashMap.put("groupId", groupId);
|
||||
scriptUtil.executeSqlScript(er, objectObjectHashMap);
|
||||
log.info("初始化开通用户");
|
||||
if (StringUtils.isNotBlank(msg.getAuthUserId())) {
|
||||
//初始化开通用户
|
||||
initAuthUser(msg.getEid(), msg.getCorpId(), msg.getAppType(), msg.getAuthUserId(), userId, msg.getDbName());
|
||||
}
|
||||
}
|
||||
|
||||
public void initAuthUser(String eid, String corpId, String appType, String authUserId, String userId, String dbName) {
|
||||
List<EnterpriseUserRole> userRoles = new ArrayList<>();
|
||||
Long roleIdByRoleEnum = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.MASTER.getRoleEnum());
|
||||
Long shopOwner = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.SHOPOWNER.getRoleEnum());
|
||||
Long subMaster = sysRoleDAO.getRoleIdByRoleEnum(eid, RoleEnum.SUB_MASTER.getRoleEnum());
|
||||
//钉钉或者企业走用户,app开通不需要
|
||||
EnterpriseUserDTO userDTO = null;
|
||||
try {
|
||||
userDTO = isvHttpRequest.getUserDetailByUserId(corpId, authUserId, appType);
|
||||
} catch (Exception e) {
|
||||
log.error("getUserDetailByUserId error", e);
|
||||
}
|
||||
EnterpriseUserDO userDO = EnterpriseUserDTO.transUserDtoToDo(userDTO);
|
||||
userDO.setMainAdmin(true);
|
||||
userDO.setIsAdmin(true);
|
||||
enterpriseUserDAO.batchInsertOrUpdate(eid, Collections.singletonList(userDO));
|
||||
userRoles.add(new EnterpriseUserRole(roleIdByRoleEnum.toString(), userId));
|
||||
userRoles.add(new EnterpriseUserRole(shopOwner.toString(), userId));
|
||||
userRoles.add(new EnterpriseUserRole(subMaster.toString(), userId));
|
||||
enterpriseUserRoleDAO.insertBatchUserRole(eid, userRoles);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user