merge master

This commit is contained in:
lifenlong
2021-05-18 08:17:14 +08:00
14 changed files with 170 additions and 312 deletions

View File

@@ -1,31 +0,0 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<artifactId>socket-api</artifactId>
<parent>
<groupId>cn.lili</groupId>
<artifactId>lili-shop-parent</artifactId>
<version>1.0.1</version>
</parent>
<dependencies>
<dependency>
<groupId>cn.lili</groupId>
<artifactId>framework</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,32 +0,0 @@
package cn.lili;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* @author Chopper
*/
@SpringBootApplication
public class SocketApiApplication extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
System.setProperty("es.set.netty.runtime.available.processors", "false");
SpringApplication.run(SocketApiApplication.class, args);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowCredentials(true)
.allowedHeaders("*") //允许任何头
.allowedOrigins("*") //允许任何域名
.allowedMethods("*"); //允许任何方法
}
}

View File

@@ -1,67 +0,0 @@
package cn.lili.scocket.listener;
import cn.hutool.json.JSONUtil;
import cn.lili.common.rocketmq.tags.OtherTagsEnum;
import cn.lili.common.utils.BeanUtil;
import cn.lili.modules.message.entity.dos.Message;
import cn.lili.modules.message.entity.enums.MessageShowType;
import cn.lili.modules.message.entity.vos.MessageShowVO;
import cn.lili.modules.message.mapper.StoreMessageMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
/**
* @author paulG
* @since 2020/12/9
**/
@Component
@CrossOrigin
@Slf4j
@RocketMQMessageListener(topic = "${lili.data.rocketmq.other-topic}", consumerGroup = "${lili.data.rocketmq.other-group}")
public class MessageSendListener implements RocketMQListener<MessageExt> {
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
@Override
public void onMessage(MessageExt messageExt) {
log.info(messageExt.getTags());
switch (OtherTagsEnum.valueOf(messageExt.getTags())) {
//站内消息提醒
case MESSAGE:
System.out.println("消息提醒");
sendNoticeMessage(messageExt);
break;
default:
break;
}
}
/**
* 给商家发送站内信息
*
* @param messageExt
*/
private void sendNoticeMessage(MessageExt messageExt) {
MessageShowVO messageVO = new MessageShowVO();
Message message = JSONUtil.toBean(new String(messageExt.getBody()), Message.class);
//构建vo
BeanUtil.copyProperties(message, messageVO);
messageVO.setType(MessageShowType.NOTICE.name());
if (message.getMessageRange().equals("ALL")) {
simpMessagingTemplate.convertAndSend("/topic/subscribe", messageVO);
} else {
for (String id : message.getUserIds()) {
simpMessagingTemplate.convertAndSendToUser("SHOP_" + id, "/queue/subscribe", messageVO);
}
}
}
}

View File

@@ -1,35 +0,0 @@
package cn.lili.scocket.listener;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
/**
* spring Security 核心配置类 Store安全配置中心
*
* @author Chopper
* @version v4.0
* @Description:
* @since 2020/11/14 16:20
*/
@Slf4j
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ScoketSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http
.authorizeRequests();
registry.antMatchers("**").permitAll();
}
}