commit message

This commit is contained in:
Chopper
2021-05-13 10:41:46 +08:00
commit 3785bdb3bb
1424 changed files with 100110 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
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

@@ -0,0 +1,68 @@
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.RequiredArgsConstructor;
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
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RocketMQMessageListener(topic = "${lili.data.rocketmq.other-topic}", consumerGroup = "${lili.data.rocketmq.other-group}")
public class MessageSendListener implements RocketMQListener<MessageExt> {
private final StoreMessageMapper storeMessageMapper;
@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

@@ -0,0 +1,35 @@
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)
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScoketSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http
.authorizeRequests();
registry.antMatchers("**").permitAll();
}
}