Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitee/dev' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/com/github/niefy/modules/wx/service/WxAccountService.java
#	src/main/resources/application-dev.yml
  • Loading branch information
nifury committed Nov 29, 2023
2 parents 633b63f + 81019ab commit 095876e
Show file tree
Hide file tree
Showing 22 changed files with 355 additions and 145 deletions.
22 changes: 11 additions & 11 deletions db/mysql-0.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CREATE TABLE `cms_article` (
`image` varchar(255) CHARACTER SET utf8 NULL DEFAULT NULL COMMENT '文章首图',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `idx_title`(`title`) USING BTREE COMMENT '标题不得重复'
) ENGINE = InnoDB AUTO_INCREMENT = 337 CHARACTER SET = utf8 COMMENT = 'CMS文章中心' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COMMENT = 'CMS文章中心' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for sys_captcha
Expand All @@ -55,7 +55,7 @@ CREATE TABLE `sys_config` (
`remark` varchar(500) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `param_key`(`param_key`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COMMENT = '系统配置信息表' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '系统配置信息表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_config
Expand All @@ -76,7 +76,7 @@ CREATE TABLE `sys_log` (
`ip` varchar(64) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT 'IP地址',
`create_date` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 324 CHARACTER SET = utf8mb4 COMMENT = '系统日志' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '系统日志' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for sys_menu
Expand All @@ -92,7 +92,7 @@ CREATE TABLE `sys_menu` (
`icon` varchar(50) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT '菜单图标',
`order_num` int(11) NULL DEFAULT NULL COMMENT '排序',
PRIMARY KEY (`menu_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 123 CHARACTER SET = utf8mb4 COMMENT = '菜单管理' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '菜单管理' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_menu
Expand Down Expand Up @@ -170,7 +170,7 @@ CREATE TABLE `sys_oss` (
`url` varchar(200) CHARACTER SET utf8mb4 NULL DEFAULT NULL COMMENT 'URL地址',
`create_date` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COMMENT = '文件上传' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '文件上传' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for sys_role
Expand Down Expand Up @@ -212,7 +212,7 @@ CREATE TABLE `sys_user` (
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`user_id`) USING BTREE,
UNIQUE INDEX `username`(`username`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COMMENT = '系统用户' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '系统用户' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of sys_user
Expand Down Expand Up @@ -272,7 +272,7 @@ CREATE TABLE `wx_msg` (
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_appid`(`appid`) USING BTREE COMMENT 'appid'
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COMMENT = '微信消息' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '微信消息' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wx_msg_reply_rule
Expand All @@ -295,7 +295,7 @@ CREATE TABLE `wx_msg_reply_rule` (
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间',
PRIMARY KEY (`rule_id`) USING BTREE,
INDEX `idx_appid`(`appid`) USING BTREE COMMENT 'appid'
) ENGINE = InnoDB AUTO_INCREMENT = 36 CHARACTER SET = utf8 COMMENT = '自动回复规则' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COMMENT = '自动回复规则' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of wx_msg_reply_rule
Expand Down Expand Up @@ -323,7 +323,7 @@ CREATE TABLE `wx_msg_template` (
UNIQUE INDEX `idx_name`(`name`) USING BTREE COMMENT '模板名称',
INDEX `idx_status`(`status`) USING BTREE COMMENT '模板状态',
INDEX `idx_appid`(`appid`) USING BTREE COMMENT 'appid'
) ENGINE = InnoDB AUTO_INCREMENT = 62 CHARACTER SET = utf8 COMMENT = '消息模板' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COMMENT = '消息模板' ROW_FORMAT = Dynamic;


-- ----------------------------
Expand All @@ -341,7 +341,7 @@ CREATE TABLE `wx_qr_code` (
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '该二维码创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_appid`(`appid`) USING BTREE COMMENT 'appid'
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COMMENT = '公众号带参二维码' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COMMENT = '公众号带参二维码' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wx_template_msg_log
Expand All @@ -360,7 +360,7 @@ CREATE TABLE `wx_template_msg_log` (
`send_result` varchar(255) CHARACTER SET utf8 NULL DEFAULT NULL COMMENT '发送结果',
PRIMARY KEY (`log_id`) USING BTREE,
INDEX `idx_appid`(`appid`) USING BTREE COMMENT 'appid'
) ENGINE = InnoDB AUTO_INCREMENT = 116250 CHARACTER SET = utf8 COMMENT = '微信模版消息发送记录' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COMMENT = '微信模版消息发送记录' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for wx_user
Expand Down
23 changes: 18 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<version>2.7.16</version>
</parent>

<properties>
Expand All @@ -29,19 +29,25 @@
<swagger.version>3.0.0</swagger.version>
<fastjson.version>2.0.28</fastjson.version>
<lombok.version>1.18.22</lombok.version>
<weixin-java.version>4.4.0</weixin-java.version>
<weixin-java.version>4.5.6.B</weixin-java.version>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
Expand Down Expand Up @@ -127,6 +133,13 @@
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.niefy.modules.wx.config;

import com.github.niefy.modules.wx.listener.WxAccountChangedMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
* @Auther: cheng.tang
* @Date: 2023/11/11
* @Description: wx-api
*/
@Configuration
public class EventMessageListenerContainerConfig {

public static final String WX_ACCOUNT_UPDATE = "event_wx_accounts_changed";

@Autowired
private WxAccountChangedMessageListener wxAccountChangedMessageListener;

@Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(50);
executor.setQueueCapacity(100);
executor.setKeepAliveSeconds(600);
executor.setThreadNamePrefix("rEvent-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return executor;
}

@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory,
ThreadPoolTaskExecutor threadPoolTaskExecutor) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(redisConnectionFactory);
container.setTaskExecutor(threadPoolTaskExecutor);
container.addMessageListener(wxAccountChangedMessageListener, new ChannelTopic(WX_ACCOUNT_UPDATE));
return container;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.niefy.modules.wx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
* @Auther: cheng.tang
* @Date: 2023/11/11
* @Description: wx-api
*/
@Configuration
public class RedisTemplateConfig {

/**
* 默认的JdkSerializationRedisSerializer序列后的结果可读性差
*
* @param redisConnectionFactory
* @return
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(RedisSerializer.string());
redisTemplate.setValueSerializer(RedisSerializer.json());
redisTemplate.setHashKeySerializer(RedisSerializer.string());
redisTemplate.setHashValueSerializer(RedisSerializer.json());
return redisTemplate;
}


}
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package com.github.niefy.modules.wx.config;

import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

@RequiredArgsConstructor
@Configuration
public class WxMpServiceConfiguration {

@Bean
public WxMpService wxMpService() {
WxMpService wxMpService = new WxMpServiceImpl();
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setMaxRetryTimes(3);
return wxMpService;
}

@Bean
public WxRedisOps wxRedisOps(StringRedisTemplate stringRedisTemplate) {
return new RedisTemplateWxRedisOps(stringRedisTemplate);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.niefy.modules.wx.listener;

import com.github.niefy.modules.wx.service.WxAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Service;

/**
* @Auther: cheng.tang
* @Date: 2023/11/11
* @Description: wx-api
*/
@Service
@Slf4j
public class WxAccountChangedMessageListener implements MessageListener {

@Autowired
private WxAccountService wxAccountService;

@Override
public void onMessage(Message message, byte[] pattern) {
log.info("receiving channel {} body {} pattern {} ", new String(message.getChannel()), new String(message.getBody()), new String(pattern));
try {
wxAccountService.loadWxMpConfigStorages();
log.info("finish ");
} catch (Exception e) {
log.error("消息处理失败了 {} ", e.getMessage());
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public R delete(@RequestBody String[] ids) {
@ApiOperation(value = "同步公众号模板")
public R syncWxTemplate(@CookieValue String appid) throws WxErrorException {
this.wxMpService.switchoverTo(appid);
msgTemplateService.syncWxTemplate(appid);
msgTemplateService.syncWxTemplate(appid, wxMpService.getTemplateMsgService().getAllPrivateTemplate());
return R.ok();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.niefy.modules.wx.manage;

import com.github.niefy.common.utils.R;
import com.github.niefy.modules.wx.config.EventMessageListenerContainerConfig;
import com.github.niefy.modules.wx.entity.WxAccount;
import com.github.niefy.modules.wx.service.WxAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
Expand All @@ -24,9 +26,13 @@
@RequestMapping("/manage/wxAccount")
@Api(tags = {"公众号账号-管理后台"})
public class WxAccountManageController {

@Autowired
private WxAccountService wxAccountService;

@Autowired
private RedisTemplate<String, Object> redisTemplate;

/**
* 列表
*/
Expand All @@ -46,9 +52,8 @@ public R list(){
@GetMapping("/info/{appid}")
@RequiresPermissions("wx:wxaccount:info")
@ApiOperation(value = "详情")
public R info(@PathVariable("id") String appid){
public R info(@PathVariable("appid") String appid){
WxAccount wxAccount = wxAccountService.getById(appid);

return R.ok().put("wxAccount", wxAccount);
}

Expand All @@ -59,8 +64,8 @@ public R info(@PathVariable("id") String appid){
@RequiresPermissions("wx:wxaccount:save")
@ApiOperation(value = "保存")
public R save(@RequestBody WxAccount wxAccount){
wxAccountService.save(wxAccount);

wxAccountService.saveOrUpdateWxAccount(wxAccount);
redisTemplate.convertAndSend(EventMessageListenerContainerConfig.WX_ACCOUNT_UPDATE, wxAccount.getAppid());
return R.ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.bean.draft.*;
import me.chanjar.weixin.mp.bean.material.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
Expand Down Expand Up @@ -99,7 +100,7 @@ public R materialNewsBatchGet(@CookieValue String appid,@RequestParam(defaultVal
@PostMapping("/materialNewsUpload")
@RequiresPermissions("wx:wxassets:save")
@ApiOperation(value = "添加图文永久素材")
public R materialNewsUpload(@CookieValue String appid,@RequestBody List<WxMpNewsArticle> articles) throws WxErrorException {
public R materialNewsUpload(@CookieValue String appid,@RequestBody List<WxMpDraftArticles> articles) throws WxErrorException {
if(articles.isEmpty()) {
return R.error("图文列表不得为空");
}
Expand All @@ -117,7 +118,7 @@ public R materialNewsUpload(@CookieValue String appid,@RequestBody List<WxMpNews
@PostMapping("/materialArticleUpdate")
@RequiresPermissions("wx:wxassets:save")
@ApiOperation(value = "修改图文素材文章")
public R materialArticleUpdate(@CookieValue String appid,@RequestBody WxMpMaterialArticleUpdate form) throws WxErrorException {
public R materialArticleUpdate(@CookieValue String appid,@RequestBody WxMpUpdateDraft form) throws WxErrorException {
if(form.getArticles()==null) {
return R.error("文章不得为空");
}
Expand Down
Loading

0 comments on commit 095876e

Please sign in to comment.