|
@@ -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("访问同步接口失败");
|
|
|
}
|
|
|
|
|
|
}
|