浏览代码

修改bug

suntianwu 3 年之前
父节点
当前提交
4ae2f9373f

+ 35 - 40
src/main/java/com/care/bms/service/DeviceService.java

@@ -379,52 +379,47 @@ public class DeviceService {
     /**
      * 同步设备
      */
-    public void synDev(String companyId) throws Exception {
+    public void synDev(String companyId) throws BDException {
 
-        try {
-            if (StringUtils.isEmpty(companyId)){
-               throw new BDException("companyId 不能为空");
-            }
-            QueryWrapper<CareOrganization> queryWrapper1 = new QueryWrapper<>();
-            queryWrapper1.lambda().eq(CareOrganization::getCompanyId,companyId);
-            CareOrganization careOrganization = this.careOrganizationService.getOne(queryWrapper1);
-            if (careOrganization == null){
-                throw new BDException("机构不存在");
-            }
+        if (StringUtils.isEmpty(companyId)){
+           throw new BDException("companyId 不能为空");
+        }
+        QueryWrapper<CareOrganization> queryWrapper1 = new QueryWrapper<>();
+        queryWrapper1.lambda().eq(CareOrganization::getCompanyId,companyId);
+        CareOrganization careOrganization = this.careOrganizationService.getOne(queryWrapper1);
+        if (careOrganization == null){
+            throw new BDException("机构不存在");
+        }
 
-            // 通过synDevUrl获取data
-            JSONObject jsonObject = HttpUtil.httpGet(synDevUrl + "?companyId=" + companyId);
-            int code = jsonObject.getInt("code");
-            if (code == 1) {
-                JSONArray data = jsonObject.getJSONArray("data");
-                Iterator it = data.iterator();
-
-                List<CareDevice> list = new ArrayList<>();
-                while (it.hasNext()) {
-                    JSONObject obj = (JSONObject) it.next();
-                    if(careOrganization != null) {
-                        CareDevice careDevice = new CareDevice();
-                        careDevice.setDevCode(obj.getStr("mdid"));
-                        careDevice.setOrgId(careOrganization.getId());
-                        careDevice.setTopic("/" + companyId + "/" + careDevice.getDevCode() + "/event");
-                        careDevice.setTopicInstall("/" + companyId + "/" + careDevice.getDevCode() + "/control");
-                        list.add(careDevice);
-                    } else {
-                        continue;
-                    }
-                }
-                if (!list.isEmpty()) {
-                    careDeviceService.synDev(list);
+        // 通过synDevUrl获取data
+        JSONObject jsonObject = HttpUtil.httpGet(synDevUrl + "?companyId=" + companyId);
+        int code = jsonObject.getInt("code");
+        if (code == 1) {
+            JSONArray data = jsonObject.getJSONArray("data");
+            Iterator it = data.iterator();
+
+            List<CareDevice> list = new ArrayList<>();
+            while (it.hasNext()) {
+                JSONObject obj = (JSONObject) it.next();
+                if(careOrganization != null) {
+                    CareDevice careDevice = new CareDevice();
+                    careDevice.setDevCode(obj.getStr("mdid"));
+                    careDevice.setOrgId(careOrganization.getId());
+                    careDevice.setTopic("/" + companyId + "/" + careDevice.getDevCode() + "/event");
+                    careDevice.setTopicInstall("/" + companyId + "/" + careDevice.getDevCode() + "/control");
+                    list.add(careDevice);
                 } else {
-                    throw new BDException("同步数据为空");
+                    continue;
                 }
-
+            }
+            if (!list.isEmpty()) {
+                careDeviceService.synDev(list);
             } else {
-                throw new BDException("访问同步接口失败");
+                throw new BDException("同步数据为空");
             }
-        } catch (Exception e) {
-            e.printStackTrace();
-            throw new BDException("同步失败",e);
+
+        } else {
+            throw new BDException("访问同步接口失败");
         }
 
     }

+ 2 - 2
src/main/java/com/care/bms/service/OrganizationService.java

@@ -194,7 +194,7 @@ public class OrganizationService {
      * @param file
      * @return  访问URL
      */
-    public String upload(MultipartFile file) throws Exception {
+    public String upload(MultipartFile file) throws BDException {
          String logo = null;
          try {
             if (file != null) {
@@ -227,7 +227,7 @@ public class OrganizationService {
      * @param vo
      */
     @Transactional(rollbackFor = Exception.class)
-    public void updateOrganization(OrganizationVO vo) throws Exception {
+    public void updateOrganization(OrganizationVO vo) throws BDException {
 
         CareOrganization careOrganization = new CareOrganization();
         BeanUtil.copyProperties(vo, careOrganization);

+ 1 - 1
src/main/java/com/care/bms/service/StationService.java

@@ -125,7 +125,7 @@ public class StationService {
         return datas;
     }
 
-    public Long addStation(StationVO vo) throws Exception {
+    public Long addStation(StationVO vo) throws BDException {
         QueryWrapper<CareStation> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(CareStation::getName,vo.getName());
         int count = this.careStationService.count(queryWrapper);