|
|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.qw.service.impl;
|
|
|
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.qw.domain.FsCompanyCustomer;
|
|
|
import com.fs.qw.mapper.FsCompanyCustomerMapper;
|
|
|
import com.fs.qw.service.IFsCompanyCustomerService;
|
|
|
@@ -30,8 +31,35 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int insertFsCompanyCustomer(FsCompanyCustomer fsCompanyCustomer) {
|
|
|
- return fsCompanyCustomerMapper.insertFsCompanyCustomer(fsCompanyCustomer);
|
|
|
+ public int insertFsCompanyCustomer(FsCompanyCustomer customer) {
|
|
|
+ try {
|
|
|
+ return fsCompanyCustomerMapper.insertFsCompanyCustomer(customer);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 判断是否为唯一键冲突(电话号码重复)
|
|
|
+ if (isDuplicatePhoneException(e)) {
|
|
|
+ throw new CustomException("电话号码已存在");
|
|
|
+ }
|
|
|
+ // 其他异常统一提示
|
|
|
+ throw new CustomException("添加失败,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断异常是否为“电话号码重复”导致的唯一键冲突
|
|
|
+ */
|
|
|
+ private boolean isDuplicatePhoneException(Exception e) {
|
|
|
+ Throwable cause = e;
|
|
|
+ while (cause != null) {
|
|
|
+ if (cause instanceof java.sql.SQLIntegrityConstraintViolationException) {
|
|
|
+ String msg = cause.getMessage();
|
|
|
+ // 根据实际约束名判断,约束名为 'fs_company_customer.uk_phone'
|
|
|
+ if (msg != null && (msg.contains("Duplicate entry") && msg.contains("uk_phone"))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cause = cause.getCause();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
@Override
|