决因为数据库连接问题导致的插入数据库异常
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -10,7 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>com.cst</groupId>
|
<groupId>com.cst</groupId>
|
||||||
<artifactId>AIDriverEEBackend</artifactId>
|
<artifactId>AIDriverEEBackend</artifactId>
|
||||||
<version>1.260502.1-SNAPSHOT</version>
|
<version>1.260504.1-SNAPSHOT</version>
|
||||||
<name>Langchain4j-rj</name>
|
<name>Langchain4j-rj</name>
|
||||||
<description>Langchain4j-rj20250803</description>
|
<description>Langchain4j-rj20250803</description>
|
||||||
<url/>
|
<url/>
|
||||||
|
|||||||
@@ -248,7 +248,10 @@ public class CustomerManagementController {
|
|||||||
@Parameter(description = "所属人姓名(模糊查询)")@RequestParam(required = false) String salesName,
|
@Parameter(description = "所属人姓名(模糊查询)")@RequestParam(required = false) String salesName,
|
||||||
@Parameter(description = "所属人电话")@RequestParam(required = false) String salesPhone,
|
@Parameter(description = "所属人电话")@RequestParam(required = false) String salesPhone,
|
||||||
@Parameter(description = "联系方式(模糊查询)")
|
@Parameter(description = "联系方式(模糊查询)")
|
||||||
@RequestParam(required = false) String contact) {
|
@RequestParam(required = false) String contact,
|
||||||
|
@Parameter(description = "联系方式(模糊查询)")
|
||||||
|
@RequestParam(required = false) String stage
|
||||||
|
) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
Page<CustomerManagement> page = new Page<>(current, size);
|
Page<CustomerManagement> page = new Page<>(current, size);
|
||||||
@@ -264,6 +267,9 @@ public class CustomerManagementController {
|
|||||||
if (contact != null && !contact.trim().isEmpty()) {
|
if (contact != null && !contact.trim().isEmpty()) {
|
||||||
queryWrapper.like(CustomerManagement::getContact, contact);
|
queryWrapper.like(CustomerManagement::getContact, contact);
|
||||||
}
|
}
|
||||||
|
if (stage != null && !stage.trim().isEmpty()) {
|
||||||
|
queryWrapper.eq(CustomerManagement::getStage, stage);
|
||||||
|
}
|
||||||
// 按创建时间倒序排列
|
// 按创建时间倒序排列
|
||||||
queryWrapper.orderByDesc(CustomerManagement::getUpdateTime);
|
queryWrapper.orderByDesc(CustomerManagement::getUpdateTime);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ import java.util.regex.Pattern;
|
|||||||
public class LbDailyUserTradeServiceImpl extends ServiceImpl<LbDailyUserTradeMapper, LbDailyUserTrade> implements ILbDailyUserTradeService {
|
public class LbDailyUserTradeServiceImpl extends ServiceImpl<LbDailyUserTradeMapper, LbDailyUserTrade> implements ILbDailyUserTradeService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(LbDailyUserTradeServiceImpl.class);
|
private static final Logger log = LoggerFactory.getLogger(LbDailyUserTradeServiceImpl.class);
|
||||||
private static final BigDecimal SERVICE_RATE = new BigDecimal("0.01");
|
private static final BigDecimal SERVICE_RATE = new BigDecimal("0.01");
|
||||||
|
/**
|
||||||
|
* MyBatis-Plus {@code saveBatch(list)} uses one SqlSession for the whole list and only closes after commit.
|
||||||
|
* Large imports can exceed Hikari {@code leakDetectionThreshold} (borrow time), producing false leak warnings.
|
||||||
|
* Chunking yields shorter per-connection holds and matches pool-friendly batch sizing.
|
||||||
|
*/
|
||||||
|
private static final int EXCEL_IMPORT_SAVE_CHUNK_SIZE = 1000;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ILbDailyUserTradeReportService lbDailyUserTradeReportService;
|
private ILbDailyUserTradeReportService lbDailyUserTradeReportService;
|
||||||
@@ -263,12 +269,20 @@ public class LbDailyUserTradeServiceImpl extends ServiceImpl<LbDailyUserTradeMap
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean saved = this.saveBatch(importList);
|
int total = importList.size();
|
||||||
if (!saved) {
|
for (int from = 0; from < total; from += EXCEL_IMPORT_SAVE_CHUNK_SIZE) {
|
||||||
log.error("导入数据保存失败,fileName={}, importCount={}", originalFilename, importList.size());
|
int to = Math.min(from + EXCEL_IMPORT_SAVE_CHUNK_SIZE, total);
|
||||||
result.put("success", false);
|
List<LbDailyUserTrade> chunk = importList.subList(from, to);
|
||||||
result.put("message", "导入失败,数据库保存异常");
|
if (!this.saveBatch(chunk)) {
|
||||||
return result;
|
log.error("导入数据保存失败,fileName={}, importCount={}, failedChunk=[{}, {})",
|
||||||
|
originalFilename, total, from, to);
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "导入失败,数据库保存异常(批次失败,可能已写入部分数据)");
|
||||||
|
result.put("importCount", from);
|
||||||
|
result.put("skipCount", skippedRows.size());
|
||||||
|
result.put("skippedRows", skippedRows);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("导入成功,fileName={}, importCount={}, skipCount={}",
|
log.info("导入成功,fileName={}, importCount={}, skipCount={}",
|
||||||
|
|||||||
@@ -98,17 +98,17 @@ spring:
|
|||||||
pool:
|
pool:
|
||||||
size: 8
|
size: 8
|
||||||
thread-name-prefix: app-scheduling-
|
thread-name-prefix: app-scheduling-
|
||||||
data:
|
# data:
|
||||||
redis:
|
# redis:
|
||||||
port: 6389
|
# port: 6389
|
||||||
host: 124.221.59.58
|
# host: 124.221.59.58
|
||||||
password: qwe123
|
# password: qwe123
|
||||||
database: 0
|
# database: 0
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# tcpKeepAlive:TCP 层定期发保活包,降低 NAT/防火墙 idle 断连(常见约 15 分钟)概率
|
# tcpKeepAlive:TCP 层定期发保活包,降低 NAT/防火墙 idle 断连(常见约 15 分钟)概率
|
||||||
# url: jdbc:mysql://124.221.59.58:3309/ai_smart_ee?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&tcpKeepAlive=true&socketTimeout=60000&connectTimeout=30000&autoReconnect=true&failOverReadOnly=false&maxReconnects=3&initialTimeout=2
|
url: jdbc:mysql://101.35.52.237:13319/ai_smart_ee?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&tcpKeepAlive=true&socketTimeout=60000&connectTimeout=30000&autoReconnect=true&failOverReadOnly=false&maxReconnects=3&initialTimeout=2
|
||||||
url: jdbc:mysql://192.168.1.44:3309/ai_smart_ee?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&tcpKeepAlive=true&autoReconnect=true&failOverReadOnly=false&maxReconnects=3&initialTimeout=2&connectTimeout=30000&socketTimeout=60000
|
# url: jdbc:mysql://192.168.1.44:3309/ai_smart_ee?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&tcpKeepAlive=true&autoReconnect=true&failOverReadOnly=false&maxReconnects=3&initialTimeout=2&connectTimeout=30000&socketTimeout=60000
|
||||||
username: root
|
username: root
|
||||||
password: cstcom.123!
|
password: cstcom.123!
|
||||||
# password: ChangAndb.123!
|
# password: ChangAndb.123!
|
||||||
|
|||||||
Reference in New Issue
Block a user