suntianwu 3 роки тому
батько
коміт
63635f4e26

+ 2 - 6
src/main/java/com/care/bms/controller/DeviceController.java

@@ -139,12 +139,8 @@ public class DeviceController {
     public Result<Object> synDev(@RequestHeader("token") String token,
             @RequestParam(value = "companyId", required =  true) String companyId) {
         try {
-            if (deviceService.synDev(companyId)){
-                return  Result.success("同步成功!");
-            } else {
-                return Result.error("同步失败!");
-            }
-
+            deviceService.synDev(companyId);
+            return  Result.success("同步成功!");
         }catch (BDException e) {
             log.error("同步设备-出现异常",e);
             return Result.error(e.getMessage());

+ 6 - 7
src/main/java/com/care/bms/service/DeviceService.java

@@ -379,17 +379,17 @@ public class DeviceService {
     /**
      * 同步设备
      */
-    public boolean synDev(String companyId) {
+    public void synDev(String companyId) throws Exception {
 
         try {
             if (StringUtils.isEmpty(companyId)){
-                return false;
+               throw new BDException("companyId 不能为空");
             }
             QueryWrapper<CareOrganization> queryWrapper1 = new QueryWrapper<>();
             queryWrapper1.lambda().eq(CareOrganization::getCompanyId,companyId);
             CareOrganization careOrganization = this.careOrganizationService.getOne(queryWrapper1);
             if (careOrganization == null){
-                return false;
+                throw new BDException("机构不存在");
             }
 
             // 通过synDevUrl获取data
@@ -415,17 +415,16 @@ public class DeviceService {
                 }
                 if (!list.isEmpty()) {
                     careDeviceService.synDev(list);
-                    return true;
                 } else {
-                    return false;
+                    throw new BDException("同步数据为空");
                 }
 
             } else {
-                return false;
+                throw new BDException("访问同步接口失败");
             }
         } catch (Exception e) {
             e.printStackTrace();
-            return false;
+            throw new BDException("同步失败",e);
         }
 
     }