点击结束录音时。如果客户信息不完整,必须补充。
This commit is contained in:
@@ -135,6 +135,8 @@ hikari:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -500,15 +500,14 @@ public class AudioManagementController {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到了客户,更新客户信息
|
||||
// 如果找到了客户,更新客户信息 ,录音总数加1
|
||||
if (customerToUpdate != null) {
|
||||
customerToUpdate.setCustomerName(audioManagement.getCustomerName());
|
||||
customerToUpdate.setContact(audioManagement.getCustomerPhone());
|
||||
customerToUpdate.setDetailedAddress(audioManagement.getRemarks());
|
||||
|
||||
customerToUpdate.setUpdateTime(LocalDateTime.now());
|
||||
customerManagementService.updateById(customerToUpdate);
|
||||
log.info("同步更新客户信息成功,客户ID: {}", customerToUpdate.getId());
|
||||
customerToUpdate.setCustomerName(audioManagement.getCustomerName());
|
||||
customerToUpdate.setContact(audioManagement.getCustomerPhone());
|
||||
customerToUpdate.setDetailedAddress(audioManagement.getRemarks());
|
||||
customerToUpdate.setUpdateTime(LocalDateTime.now());
|
||||
customerManagementService.updateById(customerToUpdate);
|
||||
log.info("同步更新客户信息成功,客户ID: {}", customerToUpdate.getId());
|
||||
} else {
|
||||
log.warn("未找到对应的客户信息,无法同步更新。customerId: {}, customerPhone: {}",
|
||||
audioManagement.getCustomerId(), audioManagement.getCustomerPhone());
|
||||
@@ -553,13 +552,43 @@ public class AudioManagementController {
|
||||
result.put("message", "录音ID不能为空");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
// 先从数据库查询完整的录音信息
|
||||
AudioManagement audioManagementFromDB = audioManagementService.getById(audioManagement.getId());
|
||||
if (audioManagementFromDB == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "录音不存在");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
// 查询客户表 customer_management,如果客户手机号或客户名称为空,不允许结束服务
|
||||
String customerId = audioManagementFromDB.getCustomerId();
|
||||
CustomerManagement customer = null;
|
||||
if (customerId != null && !customerId.trim().isEmpty()) {
|
||||
customer = customerManagementService.getById(customerId);
|
||||
if (customer != null) {
|
||||
// 检查客户手机号(contact)和客户名称(customerName)是否为空
|
||||
String contact = customer.getContact();
|
||||
String customerName = customer.getCustomerName();
|
||||
|
||||
if ((contact == null || contact.trim().isEmpty()) ||
|
||||
(customerName == null || customerName.trim().isEmpty())) {
|
||||
result.put("success", false);
|
||||
result.put("message", "客户信息不完整,请先补充客户手机号和客户名称");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<AudioManagementSegments> audioQuery = new LambdaQueryWrapper<>();
|
||||
audioQuery.eq(AudioManagementSegments::getParentId, audioManagement.getId()) ; // 关联这个id的所有录音片段
|
||||
List<AudioManagementSegments> segmentsList = audioManagementSegmentsService.list(audioQuery);
|
||||
BigDecimal total = new BigDecimal(0);
|
||||
segmentsList.forEach(segment2 ->{
|
||||
total.add(segment2.getDuration());//分钟
|
||||
});
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (AudioManagementSegments segment2 : segmentsList) {
|
||||
if (segment2.getDuration() != null) {
|
||||
total = total.add(segment2.getDuration());//分钟
|
||||
}
|
||||
}
|
||||
|
||||
AudioManagement audio = new AudioManagement();
|
||||
audio.setUpdateTime(LocalDateTime.now());
|
||||
@@ -569,6 +598,26 @@ public class AudioManagementController {
|
||||
audio.setEndTime( LocalDateTime.now());
|
||||
|
||||
boolean success = audioManagementService.updateById(audio);
|
||||
|
||||
// 根据 customerId,把客户 customer_management 表的 recording_count 录音数加 1
|
||||
try {
|
||||
Integer recordingCount = customer.getRecordingCount();
|
||||
if (recordingCount == null) {
|
||||
recordingCount = 1;
|
||||
} else {
|
||||
recordingCount = recordingCount + 1;
|
||||
}
|
||||
CustomerManagement customerForUpdate = new CustomerManagement();
|
||||
customerForUpdate.setId(customer.getId());
|
||||
customerForUpdate.setRecordingCount(recordingCount);
|
||||
customerForUpdate.setUpdateTime(LocalDateTime.now());
|
||||
customerManagementService.updateById(customerForUpdate);
|
||||
log.info("更新客户录音数成功,客户ID: {}, 录音数: {}", customerId, recordingCount);
|
||||
} catch (Exception e) {
|
||||
// 客户录音数更新失败不影响录音服务结束的结果,只记录日志
|
||||
log.error("更新客户录音数时发生异常: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
|
||||
if (success) {
|
||||
result.put("success", true);
|
||||
|
||||
Reference in New Issue
Block a user