Jelajahi Sumber

完善客户信息表+患者信息表逻辑

cgp 1 hari lalu
induk
melakukan
dca62fa9b2

+ 3 - 3
fs-company/src/main/java/com/fs/company/controller/qw/FsCompanyCustomerController.java

@@ -89,7 +89,7 @@ public class FsCompanyCustomerController extends BaseController {
      */
     @PostMapping
     public AjaxResult add(@RequestBody FsCompanyCustomer fsCompanyCustomer) {
-        return toAjax(fsCompanyCustomerService.insertFsCompanyCustomer(fsCompanyCustomer));
+        return AjaxResult.success(fsCompanyCustomerService.insertFsCompanyCustomer(fsCompanyCustomer));
     }
 
     /**
@@ -97,7 +97,7 @@ public class FsCompanyCustomerController extends BaseController {
      */
     @PutMapping
     public AjaxResult edit(@RequestBody FsCompanyCustomer fsCompanyCustomer) {
-        return toAjax(fsCompanyCustomerService.updateFsCompanyCustomer(fsCompanyCustomer));
+        return AjaxResult.success(fsCompanyCustomerService.updateFsCompanyCustomer(fsCompanyCustomer));
     }
 
     /**
@@ -105,7 +105,7 @@ public class FsCompanyCustomerController extends BaseController {
      */
     @DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable Long[] ids) {
-        return toAjax(fsCompanyCustomerService.deleteFsCompanyCustomerByIds(ids));
+        return AjaxResult.success(fsCompanyCustomerService.deleteFsCompanyCustomerByIds(ids));
     }
 
     /**

+ 30 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsDoctorPatientServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.his.service.impl;
 
+import com.fs.common.exception.CustomException;
 import com.fs.his.domain.FsDoctorPatient;
 import com.fs.his.mapper.FsDoctorPatientMapper;
 import com.fs.his.service.IFsDoctorPatientService;
@@ -31,7 +32,35 @@ public class FsDoctorPatientServiceImpl implements IFsDoctorPatientService {
 
     @Override
     public int insertFsDoctorPatient(FsDoctorPatient fsDoctorPatient) {
-        return fsDoctorPatientMapper.insertFsDoctorPatient(fsDoctorPatient);
+        try {
+            return fsDoctorPatientMapper.insertFsDoctorPatient(fsDoctorPatient);
+        } 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

+ 30 - 2
fs-service/src/main/java/com/fs/qw/service/impl/FsCompanyCustomerServiceImpl.java

@@ -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