更改 mysql 数据库为 原生数据库,放弃 docker 容器数据库

This commit is contained in:
Jack 2025-07-29 19:54:05 +08:00
parent d6a727f9fa
commit 30dc0e976e
11 changed files with 77 additions and 41 deletions

View File

@ -43,10 +43,10 @@ cd /data/sh
```shell ```shell
进入 docker 控制台 进入 docker 控制台
cd /var/lib/mysql cd /var/lib/mysql
mysqldump -u root -p mall_prod | gzip > mall_prod_20250723.sql.gz mysqldump -u root -p mall_prod | gzip > mall_prod_20250729.sql.gz
在宿主机找到: 在宿主机找到:
/data/mysql/data/mall_prod_20250630.sql.gz /data/mysql/data/mall_prod_20250729.sql.gz
``` ```
清除 docker 日志 清除 docker 日志

View File

@ -22,10 +22,17 @@ public class DealUserAnalyticsListener {
@Autowired @Autowired
private AccountUserAnalyticsService accountUserAnalyticsService; private AccountUserAnalyticsService accountUserAnalyticsService;
// @RabbitHandler
// public void listener(byte[] data, Channel channel, Message message) throws IOException, InterruptedException {
// // 将byte[]转换为String然后调用现有的处理逻辑
// String dataStr = new String(data, StandardCharsets.UTF_8);
// listener(dataStr, channel, message);
// }
@RabbitHandler @RabbitHandler
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException { public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
AccountUserAnalytics accountUserAnalytics = JSONUtil.toBean(data, AccountUserAnalytics.class); AccountUserAnalytics accountUserAnalytics = JSONUtil.toBean(data, AccountUserAnalytics.class);
String messageId = message.getMessageProperties().getMessageId(); // String messageId = message.getMessageProperties().getMessageId();
try { try {
boolean flag = accountUserAnalyticsService.saveOrUpdate(accountUserAnalytics); boolean flag = accountUserAnalyticsService.saveOrUpdate(accountUserAnalytics);

View File

@ -22,10 +22,17 @@ public class DealUserInfoListener {
@Autowired @Autowired
private AccountUserInfoService accountUserInfoService; private AccountUserInfoService accountUserInfoService;
// @RabbitHandler
// public void listener(byte[] data, Channel channel, Message message) throws IOException, InterruptedException {
// // 将byte[]转换为String然后调用现有的处理逻辑
// String dataStr = new String(data, StandardCharsets.UTF_8);
// listener(dataStr, channel, message);
// }
@RabbitHandler @RabbitHandler
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException { public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
AccountUserInfo accountUserInfo = JSONUtil.toBean(data, AccountUserInfo.class); AccountUserInfo accountUserInfo = JSONUtil.toBean(data, AccountUserInfo.class);
String messageId = message.getMessageProperties().getMessageId(); // String messageId = message.getMessageProperties().getMessageId();
try { try {
boolean flag = accountUserInfoService.saveOrUpdate(accountUserInfo); boolean flag = accountUserInfoService.saveOrUpdate(accountUserInfo);

View File

@ -22,10 +22,17 @@ public class ExperienceListener {
@Autowired @Autowired
private AccountUserInfoService accountUserInfoService; private AccountUserInfoService accountUserInfoService;
// @RabbitHandler
// public void listener(byte[] data, Channel channel, Message message) throws IOException, InterruptedException {
// // 将byte[]转换为String然后调用现有的处理逻辑
// String dataStr = new String(data, StandardCharsets.UTF_8);
// listener(dataStr, channel, message);
// }
@RabbitHandler @RabbitHandler
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException { public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
ExperienceTO experienceTO = JSONUtil.toBean(data, ExperienceTO.class); ExperienceTO experienceTO = JSONUtil.toBean(data, ExperienceTO.class);
String messageId = message.getMessageProperties().getMessageId(); // String messageId = message.getMessageProperties().getMessageId();
try { try {
boolean flag = accountUserInfoService.experience(experienceTO.getUser_id(), experienceTO.getExp(), experienceTO.getExp_type_id(), experienceTO.getDesc()); boolean flag = accountUserInfoService.experience(experienceTO.getUser_id(), experienceTO.getExp(), experienceTO.getExp_type_id(), experienceTO.getDesc());

View File

@ -22,10 +22,17 @@ public class UpgradeUserLevelListener {
@Autowired @Autowired
private AccountUserInfoService accountUserInfoService; private AccountUserInfoService accountUserInfoService;
// @RabbitHandler
// public void listener(byte[] data, Channel channel, Message message) throws IOException, InterruptedException {
// // 将byte[]转换为String然后调用现有的处理逻辑
// String dataStr = new String(data, StandardCharsets.UTF_8);
// listener(dataStr, channel, message);
// }
@RabbitHandler @RabbitHandler
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException { public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
UserLevelTO userLevelTO = JSONUtil.toBean(data, UserLevelTO.class); UserLevelTO userLevelTO = JSONUtil.toBean(data, UserLevelTO.class);
String messageId = message.getMessageProperties().getMessageId(); // String messageId = message.getMessageProperties().getMessageId();
try { try {
boolean flag = accountUserInfoService.checkUpdateUserLevel(userLevelTO.getUser_id(), userLevelTO.getUser_exp_total(), userLevelTO.getUser_fans_total(), userLevelTO.getUser_spend_total(), 0, 0, 0); boolean flag = accountUserInfoService.checkUpdateUserLevel(userLevelTO.getUser_id(), userLevelTO.getUser_exp_total(), userLevelTO.getUser_fans_total(), userLevelTO.getUser_spend_total(), 0, 0, 0);

View File

@ -7,8 +7,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -89,10 +89,14 @@ public class IpUtil implements ApplicationRunner {
try { try {
List<String> split = Arrays.asList(ss.split("\\|")); List<String> split = Arrays.asList(ss.split("\\|"));
if (split.size() >= 4) { String[] parts = ss.split("\\|");
districtVo.setCountry(split.get(0)); // 设置国家
districtVo.setProvince(split.get(2)); // 设置省份 // 检查分割后的数组长度避免数组越界
districtVo.setCity(split.get(3)); // 设置城市 if (parts.length >= 4) {
// 对每个部分进行非空检查防止空指针异常
districtVo.setCountry(parts[0] != null ? parts[0] : ""); // 设置国家
districtVo.setProvince(parts[2] != null ? parts[2] : ""); // 设置省份
districtVo.setCity(parts[3] != null ? parts[3] : ""); // 设置城市
} else { } else {
log.debug("IP{} 解析结果格式不符合要求,原始数据: {}", ip, ss); log.debug("IP{} 解析结果格式不符合要求,原始数据: {}", ip, ss);
return null; return null;
@ -116,13 +120,13 @@ public class IpUtil implements ApplicationRunner {
* @throws Exception 加载过程中可能抛出的异常 * @throws Exception 加载过程中可能抛出的异常
*/ */
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) {
try { try {
log.info("开始加载 ip2region 数据文件"); log.info("开始加载 ip2region 数据文件");
ClassPathResource resource = new ClassPathResource("static/ip/ip2region.xdb"); ClassPathResource resource = new ClassPathResource("static/ip/ip2region.xdb");
InputStream inputStream = resource.getInputStream(); InputStream inputStream = resource.getInputStream();
// 使用 ByteArrayOutputStream 替代 available() 方法来正确读取文件内容 // 使用 ByteArrayOutputStream 替代 available() 方法来正确读取文件内容
java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream(); java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
int nRead; int nRead;
@ -132,18 +136,13 @@ public class IpUtil implements ApplicationRunner {
} }
buffer.flush(); buffer.flush();
byte[] bytes = buffer.toByteArray(); byte[] bytes = buffer.toByteArray();
inputStream.close(); inputStream.close();
searcher = Searcher.newWithBuffer(bytes); searcher = Searcher.newWithBuffer(bytes);
log.info("成功加载 ip2region 数据文件。"); log.info("成功加载 ip2region 数据文件。");
// 测试本地IP地址解析 } catch (ArrayIndexOutOfBoundsException e) {
try { log.error("解析IP地址的地区信息时发生数组越界异常原始数据: {}", e);
String testResult = searcher.search("127.0.0.1");
log.info("测试本地IP解析结果: {}", testResult);
} catch (Exception e) {
log.warn("本地IP测试解析失败: {}", e.getMessage());
}
} catch (IOException e) { } catch (IOException e) {
log.error("加载 ip2region 失败。", e); log.error("加载 ip2region 失败。", e);
} catch (Exception e) { } catch (Exception e) {

View File

@ -41,14 +41,7 @@ public class DelayMessageReceiver {
@Lazy @Lazy
@Resource @Resource
private PushMessageService pushMessageService; private PushMessageService pushMessageService;
@RabbitListener(queues = MqConstant.DEAD_LETTER_QUEUE_NAME)
// public void handleExpiredMessage(byte[] data, Channel channel, Message message) {
// // 将byte[]转换为String然后调用现有的处理逻辑
// String dataStr = new String(data, StandardCharsets.UTF_8);
// handleExpiredMessage(dataStr, channel, message);
// }
/** /**
* 监听死信队列处理过期的延迟消息 * 监听死信队列处理过期的延迟消息
* *

View File

@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
@Service @Service
@Slf4j @Slf4j
@ -22,6 +23,13 @@ public class MessageListener {
@Autowired @Autowired
private MessageService messageService; private MessageService messageService;
@RabbitHandler
public void listener(byte[] data, Channel channel, Message message) {
// 将byte[]转换为String然后调用现有的处理逻辑
String dataStr = new String(data, StandardCharsets.UTF_8);
listener(dataStr, channel, message);
}
@RabbitHandler @RabbitHandler
public void listener(String data, Channel channel, Message message) { public void listener(String data, Channel channel, Message message) {
MsgTO msgTO = JSONUtil.toBean(data, MsgTO.class); MsgTO msgTO = JSONUtil.toBean(data, MsgTO.class);

View File

@ -66,8 +66,7 @@ public class OrderPayedListener {
@RabbitHandler @RabbitHandler
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException { public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
String messageId = message.getMessageProperties().getMessageId(); // String messageId = message.getMessageProperties().getMessageId();
List<String> order_id_row = Convert.toList(String.class, data); List<String> order_id_row = Convert.toList(String.class, data);
try { try {

View File

@ -443,9 +443,9 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl<ShopPageBaseMapper,
Map product_item_row = product_item_opl.get(); Map product_item_row = product_item_opl.get();
// 获取商品实时数据 // 获取商品实时数据
String path=""; String path = "";
String product_name=""; String product_name = "";
Map product_basic_info_row = shopProductBaseService.getProductBasicInfo(Convert.toLong(product_item_row.get("product_id")),Convert.toInt(product_item_row.get("store_id"))); Map product_basic_info_row = shopProductBaseService.getProductBasicInfo(Convert.toLong(product_item_row.get("product_id")), Convert.toInt(product_item_row.get("store_id")));
if (product_basic_info_row != null) { if (product_basic_info_row != null) {
path = product_basic_info_row.get("product_image").toString(); path = product_basic_info_row.get("product_image").toString();
product_name = product_basic_info_row.get("product_name").toString(); product_name = product_basic_info_row.get("product_name").toString();
@ -481,11 +481,11 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl<ShopPageBaseMapper,
((JSONObject) item).set("item_unit_points", int_item_unit_points); ((JSONObject) item).set("item_unit_points", int_item_unit_points);
((JSONObject) item).set("item_unit_sp", int_item_unit_sp); ((JSONObject) item).set("item_unit_sp", int_item_unit_sp);
if(StrUtil.isNotBlank(path)) { if (StrUtil.isNotBlank(path)) {
((JSONObject) item).set("path", path); ((JSONObject) item).set("path", path);
} }
if(StrUtil.isNotBlank(product_name)) { if (StrUtil.isNotBlank(product_name)) {
((JSONObject) item).set("name", product_name); ((JSONObject) item).set("name", product_name);
} }
} }
@ -548,20 +548,29 @@ public class ShopPageBaseServiceImpl extends BaseServiceImpl<ShopPageBaseMapper,
List<Long> item_id_104 = new ArrayList<>(); List<Long> item_id_104 = new ArrayList<>();
for (Object datum : data) { for (Object datum : data) {
JSONObject jsonObject = cn.hutool.json.JSONUtil.parseObj(datum); JSONObject jsonObject = JSONUtil.parseObj(datum);
List ids = Convert.toList(jsonObject.get("ids")); List ids = Convert.toList(jsonObject.get("ids"));
item_id_104.addAll(ids); item_id_104.addAll(ids);
} }
List<Long> item_ids = new ArrayList<>(); List<Long> item_ids = new ArrayList<>();
if(CollUtil.isNotEmpty(item_id_104)) { if (CollUtil.isNotEmpty(item_id_104)) {
List<Serializable> item_ids_key = shopProductItemService.findKey(new QueryWrapper<ShopProductItem>().in("item_id", item_id_104).eq("item_enable", 1001)); List<Serializable> item_ids_key = shopProductItemService.findKey(new QueryWrapper<ShopProductItem>().in("item_id", item_id_104).eq("item_enable", 1001));
if (CollUtil.isNotEmpty(item_ids_key)) { if (CollUtil.isNotEmpty(item_ids_key)) {
item_ids = Convert.toList(Long.class, item_ids_key); item_ids = Convert.toList(Long.class, item_ids_key);
} }
} }
// List<Long> item_ids = new ArrayList<>();
// QueryWrapper<ShopProductItem> shopProductItemQueryWrapper = new QueryWrapper<>();
// itemEQueryWrapper.in("item_id", item_id_104);
// itemEQueryWrapper.eq("item_enable", 1001);
// List<Serializable> item_ids_key = shopProductItemService.findKey(shopProductItemQueryWrapper);
// if (CollUtil.isNotEmpty(item_ids_key)) {
// item_ids = Convert.toList(Long.class, item_ids_key);
// }
JSONArray data1 = new JSONArray(); JSONArray data1 = new JSONArray();
for (Object datum : data) { for (Object datum : data) {
JSONObject jsonObject = JSONUtil.parseObj(datum); JSONObject jsonObject = JSONUtil.parseObj(datum);

View File

@ -478,10 +478,10 @@
<sentinel.transport.dashboard>172.16.0.11:8718</sentinel.transport.dashboard> <sentinel.transport.dashboard>172.16.0.11:8718</sentinel.transport.dashboard>
<!-- mysql配置 --> <!-- mysql配置 -->
<mysql.host>172.16.0.11</mysql.host> <mysql.host>172.16.0.11</mysql.host>
<mysql.port>3306</mysql.port> <mysql.port>13306</mysql.port>
<mysql.db>mall_prod</mysql.db> <mysql.db>mall_prod</mysql.db>
<mysql.user>webprod</mysql.user> <mysql.user>webprod</mysql.user>
<mysql.pwd>v9W2ER6KG9HVtH1mjAytRvdr</mysql.pwd> <mysql.pwd>J1XivNvAcR21}pA6Cysm.E29</mysql.pwd>
<mysql.driver>com.mysql.cj.jdbc.Driver</mysql.driver> <mysql.driver>com.mysql.cj.jdbc.Driver</mysql.driver>
<!-- redis5配置 --> <!-- redis5配置 -->
<!-- <redis.host>172.16.0.11</redis.host>--> <!-- <redis.host>172.16.0.11</redis.host>-->