From a4fb4bef4f6c74df84f0005e9f72b2bd166b179f Mon Sep 17 00:00:00 2001 From: YXY <932687738@qq.com> Date: Mon, 13 Mar 2023 20:41:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E7=99=BD=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumer/LarkApplicationRunner.java | 107 ++++++++++++++++++ .../controller/EventController.java | 2 +- .../controller/EventControllers.java | 3 +- .../com/ruoyi/flyingbook/domain/Event.java | 14 ++- .../ruoyi/flyingbook/mapper/EventMapper.java | 6 + .../src/main/resources/mapper/EventMapper.xml | 21 +++- .../framework/config/SecurityConfig.java | 4 +- 7 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/consumer/LarkApplicationRunner.java diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/consumer/LarkApplicationRunner.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/consumer/LarkApplicationRunner.java new file mode 100644 index 0000000..75a33e3 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/consumer/LarkApplicationRunner.java @@ -0,0 +1,107 @@ +package com.ruoyi.flyingbook.consumer; + +import cn.hutool.core.thread.ThreadFactoryBuilder; +import com.ruoyi.common.constant.RedisConstants; +import com.ruoyi.common.enums.EventOperateStatus; +import com.ruoyi.flyingbook.domain.Event; +import com.ruoyi.flyingbook.mapper.EventMapper; +import com.ruoyi.flyingbook.service.IEventService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.compress.utils.Lists; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author yuxiangyong + * @create 2023-03-12 23:04 + */ +@Slf4j +@Component +public class LarkApplicationRunner implements ApplicationRunner { + + + + /** + * 核心线程数 + */ + private static final Integer CORE_POOL_SIZE = 1; + /** + * 最大线程数 + */ + private static final Integer MAX_POOL_SIZE = 1; + /** + * 存活时间 + */ + private static final Integer KEEP_ALIVE_TIME = 30; + + /** + * 队列长度 + */ + private static final Integer QUEUE_SIZE = 20; + /** + * 线程睡眠时间 + */ + private static final Integer WAIT_TIME = 5000; + + @Autowired + private EventMapper eventMapper; + + ThreadPoolExecutor threadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, + TimeUnit.SECONDS, new LinkedBlockingQueue(QUEUE_SIZE), new ThreadPoolExecutor.AbortPolicy()); + + @Override + public void run(ApplicationArguments args) throws Exception { + //这里用线程池,后续如果出现量大的情况下可以调整 +// threadPool.execute(() -> { +// +// while (true) { +// List statusList = Arrays.asList(EventOperateStatus.PENDING.getCode(),EventOperateStatus.FAIL.getCode()); +// List eventList = eventMapper.queryListOperate(statusList); +// if (CollectionUtils.isEmpty(eventList)) { +// try { +// // 没有订单,休息一下 +// Thread.sleep(WAIT_TIME); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } else { +// try { +// +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// }); + } + + private void operate(Event event){ + if (StringUtils.isNotBlank(event.getMessage())){ + queryAndOperate(event); + }else { + executeOperate(event); + } + } + + + private void queryAndOperate(Event event){ + + } + + private void executeOperate(Event event){ + + } +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventController.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventController.java index 0de8c0d..4b89f01 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventController.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventController.java @@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; @Slf4j @RestController -@RequestMapping("/event/test1") public class EventController extends BaseController { @Autowired @@ -30,6 +29,7 @@ public class EventController extends BaseController { log.error("没有值"); return result; } + log.info("/event/test1/approval request:{} encrypt:{}", jsonObject.toJSONString(), result); if (jsonObject.containsKey("encrypt")) { result = DecryptUtil.decrypt(jsonObject.getString("encrypt")); log.info("/event/test1/approval request:{} encrypt:{}", jsonObject.toJSONString(), result); diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventControllers.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventControllers.java index 6c6cdca..5d649e0 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventControllers.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EventControllers.java @@ -31,7 +31,6 @@ import java.util.Map; @Slf4j @RestController -@RequestMapping("/event/test2") public class EventControllers { @@ -174,7 +173,7 @@ public class EventControllers { private ServletAdapter servletAdapter; //3. 创建路由处理器 - @PostMapping("/approval") + @PostMapping("/approval2") public void event(HttpServletRequest request, HttpServletResponse response) throws Throwable { //3.1 回调扩展包提供的事件回调处理器 diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/Event.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/Event.java index 56a86a8..a125290 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/Event.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/Event.java @@ -17,7 +17,8 @@ public class Event extends BaseEntity /** $column.columnComment */ private Long id; - + private Integer numbers; + private String eventCode; /** $column.columnComment */ @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private String message; @@ -26,7 +27,15 @@ public class Event extends BaseEntity @Excel(name = "pendingsuccessfaild") private String flag; - public void setId(Long id) + public Integer getNumbers() { + return numbers; + } + + public void setNumbers(Integer numbers) { + this.numbers = numbers; + } + + public void setId(Long id) { this.id = id; } @@ -59,6 +68,7 @@ public class Event extends BaseEntity return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("id", getId()) .append("message", getMessage()) + .append("numbers", getMessage()) .append("createBy", getCreateBy()) .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/EventMapper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/EventMapper.java index 3f237e4..4cd1e18 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/EventMapper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/EventMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.flyingbook.mapper; import com.ruoyi.flyingbook.domain.Event; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -60,4 +61,9 @@ public interface EventMapper * @return 结果 */ public int deleteEventByIds(Long[] ids); + + /** + * 查询需要推送的列表信息 + */ + public List queryListOperate(@Param("statusList") List statusList); } diff --git a/ruoyi-flyingbook/src/main/resources/mapper/EventMapper.xml b/ruoyi-flyingbook/src/main/resources/mapper/EventMapper.xml index 324b436..0a792d3 100644 --- a/ruoyi-flyingbook/src/main/resources/mapper/EventMapper.xml +++ b/ruoyi-flyingbook/src/main/resources/mapper/EventMapper.xml @@ -6,7 +6,9 @@ + + @@ -17,7 +19,9 @@ select id, + event_code, message, + numbers, create_by, create_time, update_by, @@ -43,7 +47,9 @@ insert into event + event_code, message, + numbers, create_by, create_time, update_by, @@ -52,7 +58,9 @@ remark, + #{event_code}, #{message}, + #{numbers}, #{createBy}, #{createTime}, #{updateBy}, @@ -65,7 +73,9 @@ update event - message = #{message}, + message = #{event_code}, + message = #{message}, + message = #{numbers}, create_by = #{createBy}, create_time = #{createTime}, update_by = #{updateBy}, @@ -88,4 +98,13 @@ #{id} + + \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index c8e1c1b..e618f63 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter // 过滤请求 .authorizeRequests() // 对于登录login 验证码captchaImage 允许匿名访问 - .antMatchers("/login", "/captchaImage").anonymous() + .antMatchers("/login", "/captchaImage", "/approval", "/approval2").anonymous() .antMatchers( HttpMethod.GET, "/*.html", @@ -115,7 +115,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter .antMatchers("/druid/**").anonymous() .antMatchers("/flowable/**").permitAll() .antMatchers("/socket/**").permitAll() - .antMatchers("/event/**").permitAll() + .antMatchers("//event/**").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and()