|
@@ -1,6 +1,8 @@
|
|
package com.huimv.admin.service.impl;
|
|
package com.huimv.admin.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.codec.Base64;
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
@@ -36,10 +38,9 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.text.NumberFormat;
|
|
import java.text.NumberFormat;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -307,7 +308,6 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
|
|
@Transactional
|
|
@Transactional
|
|
public Result sync(Map<String, Integer> params) throws Exception {
|
|
public Result sync(Map<String, Integer> params) throws Exception {
|
|
Integer farmId = params.get("farmId");
|
|
Integer farmId = params.get("farmId");
|
|
- this.remove(new QueryWrapper<EnvDevice>().eq("farm_id",farmId));
|
|
|
|
//获取所有栏舍
|
|
//获取所有栏舍
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
String s = HttpClientSSLUtils.doPost("https://yzwlw.loongk.com/mobile/login?username=江西增鑫&password=21218cca77804d2ba1922c33e0151105", JSON.toJSONString(map));
|
|
String s = HttpClientSSLUtils.doPost("https://yzwlw.loongk.com/mobile/login?username=江西增鑫&password=21218cca77804d2ba1922c33e0151105", JSON.toJSONString(map));
|
|
@@ -319,9 +319,27 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
|
|
headers.add("Authorization",encode);
|
|
headers.add("Authorization",encode);
|
|
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
|
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
|
List<DataShacks> shacks = loginDto.getData().getShacks();
|
|
List<DataShacks> shacks = loginDto.getData().getShacks();
|
|
- for (DataShacks shack : shacks) {
|
|
|
|
- syncConfig(shack.getId(),requestEntity,farmId);
|
|
|
|
|
|
+ // 不能删除,需做比较
|
|
|
|
+ List<String> zengXinDeviceId = shacks.stream().map(DataShacks::getId).collect(Collectors.toList());
|
|
|
|
+ List<String> huatongDeviceId = envDeviceMapper.selectDeviceCodeByfarmId(farmId);
|
|
|
|
+
|
|
|
|
+ CopyOnWriteArrayList<String> zengXinDeviceIdCopy = ListUtil.toCopyOnWriteArrayList(zengXinDeviceId);
|
|
|
|
+ CopyOnWriteArrayList<String> huatongDeviceIdCopy = ListUtil.toCopyOnWriteArrayList(huatongDeviceId);
|
|
|
|
+ //新增的设备
|
|
|
|
+ zengXinDeviceIdCopy.removeAll(huatongDeviceId);
|
|
|
|
+ //新增
|
|
|
|
+ if (zengXinDeviceIdCopy.size() >0){
|
|
|
|
+ for (String deviceId : zengXinDeviceIdCopy) {
|
|
|
|
+ syncConfig(deviceId,requestEntity,farmId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //需要删除的设备
|
|
|
|
+ huatongDeviceIdCopy.removeAll(zengXinDeviceId);
|
|
|
|
+ if (huatongDeviceIdCopy.size() >0){
|
|
|
|
+ this.remove(new QueryWrapper<EnvDevice>().in("device_code",huatongDeviceIdCopy));
|
|
}
|
|
}
|
|
|
|
+ System.out.println("zengxin:"+zengXinDeviceIdCopy);
|
|
|
|
+ System.out.println(huatongDeviceIdCopy);
|
|
return new Result(10000,"同步成功",false);
|
|
return new Result(10000,"同步成功",false);
|
|
}
|
|
}
|
|
|
|
|