|
|
@@ -13,13 +13,19 @@ import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+/**
|
|
|
+ * 用于预计算房间-租赁详情的方法<br/>
|
|
|
+ * 线程不安全,请在调用时使用这个类下的LOCK做全局锁<br/>
|
|
|
+ * 将多个楼宇放进一个对象会影响速度,请一个楼宇一个对象
|
|
|
+ */
|
|
|
public class DataPreCounter {
|
|
|
|
|
|
public static final Object LOCK = new Object();
|
|
|
|
|
|
/**
|
|
|
* 注意输入的数据有副作用
|
|
|
- * @param allPark 所有参与的park数据,为避免数据不完整,请提供整个产业园的数据
|
|
|
+ *
|
|
|
+ * @param allPark 所有参与的park数据,为避免数据不完整,请提供整个产业园的数据
|
|
|
* @param allLease 所有参与的租赁,提供所有涉及的房间的所有数据即可,如果数据出现房间级的不完整,就会导致结果有误
|
|
|
*/
|
|
|
public DataPreCounter(List<JSONObject> allPark, List<JSONObject> allLease, LocalDate now) {
|
|
|
@@ -53,19 +59,27 @@ public class DataPreCounter {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public Set<JSONObject> getRoomsWithCode(Collection<String> roomCodes){
|
|
|
- return allRoom.stream()
|
|
|
- .filter(v->roomCodes.contains(v.getString(String.valueOf(ParkKey.c_park_code))))
|
|
|
+ public Set<JSONObject> getRoomsWithCode(Collection<String> roomCodes, List<JSONObject> range) {
|
|
|
+ if (roomCodes == null || roomCodes.isEmpty() || range == null || range.isEmpty()) {
|
|
|
+ return Collections.emptySet();
|
|
|
+ }
|
|
|
+ return range.stream()
|
|
|
+ .filter(v -> roomCodes.contains(v.getString(String.valueOf(ParkKey.c_park_code))))
|
|
|
.collect(Collectors.toSet());
|
|
|
}
|
|
|
|
|
|
+ public Set<JSONObject> getRoomsWithCode(Collection<String> roomCodes) {
|
|
|
+ return getRoomsWithCode(roomCodes, allRoom);
|
|
|
+ }
|
|
|
+
|
|
|
public List<JSONObject> getParkNeedUpload() {
|
|
|
- return allPark.stream().filter(v->parkNeedUploadId.contains(v.getString("id"))).collect(Collectors.toList());
|
|
|
+ return allPark.stream().filter(v -> parkNeedUploadId.contains(v.getString("id"))).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
public List<JSONObject> getLeaseNeedUpload() {
|
|
|
- return allLease.stream().filter(v->leaseNeedUploadId.contains(v.getString("id"))).collect(Collectors.toList());
|
|
|
+ return allLease.stream().filter(v -> leaseNeedUploadId.contains(v.getString("id"))).collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
private enum LeaseKey {
|
|
|
c_room_code, c_enterprise_code, c_start_date, c_end_date, c_lease_purpose, c_is_latest_lease, c_lease_status, update_time, c_enterprise_name
|
|
|
}
|
|
|
@@ -128,49 +142,71 @@ public class DataPreCounter {
|
|
|
private final List<JSONObject> allLease;
|
|
|
|
|
|
|
|
|
-
|
|
|
- private final LocalDate now ;
|
|
|
+ private final LocalDate now;
|
|
|
|
|
|
/**
|
|
|
* 运行预统计,有副作用,注意只能运行提供了租赁数据的房间,你可以从parkNeedUpload和leaseNeedUpload中获取所有更新过的数据
|
|
|
+ *
|
|
|
* @param roomRange 统计的范围
|
|
|
*/
|
|
|
- public void run(Collection<JSONObject> roomRange){
|
|
|
- synchronized (LOCK) {
|
|
|
- if (roomRange==null) {
|
|
|
- roomRange = allRoom;
|
|
|
- }
|
|
|
- //更新并检查所有需更新房间
|
|
|
- List<JSONObject> updatedRooms = roomRange.stream()
|
|
|
- .filter(this::countRoom).collect(Collectors.toList());
|
|
|
- //按层级统计面积
|
|
|
- //楼层
|
|
|
- List<JSONObject> fatherLcs = findFathers(updatedRooms,allLc);
|
|
|
- //楼栋
|
|
|
- List<JSONObject> fatherLds = findFathers(fatherLcs,allLd);
|
|
|
- //楼宇/产业园
|
|
|
- List<JSONObject> fatherLys = findFathers(fatherLds,allLy);
|
|
|
- fatherLds.forEach(this::countParkByChild);
|
|
|
- fatherLcs.forEach(this::countParkByChild);
|
|
|
- fatherLys.forEach(this::countParkByChild);
|
|
|
+ public void run(Collection<JSONObject> roomRange) {
|
|
|
+ if (roomRange == null) {
|
|
|
+ roomRange = allRoom;
|
|
|
}
|
|
|
-
|
|
|
+ //更新并检查所有需更新房间
|
|
|
+ List<JSONObject> updatedRooms = roomRange.stream()
|
|
|
+ .filter(this::countRoom).collect(Collectors.toList());
|
|
|
+ //按层级统计面积
|
|
|
+ //楼层
|
|
|
+ List<JSONObject> fatherLcs = findFathers(updatedRooms, allLc);
|
|
|
+ //楼栋
|
|
|
+ List<JSONObject> fatherLds = findFathers(fatherLcs, allLd);
|
|
|
+ //楼宇/产业园
|
|
|
+ List<JSONObject> fatherLys = findFathers(fatherLds, allLy);
|
|
|
+ fatherLds.forEach(this::countParkByChild);
|
|
|
+ fatherLcs.forEach(this::countParkByChild);
|
|
|
+ fatherLys.forEach(this::countParkByChild);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 运行预统计,有副作用,注意只能运行提供了租赁数据的房间,你可以从parkNeedUpload和leaseNeedUpload中获取所有更新过的数据
|
|
|
*/
|
|
|
- public void run(){
|
|
|
+ public void run() {
|
|
|
run(allRoom);
|
|
|
}
|
|
|
|
|
|
- private List<JSONObject> findFathers(Collection<JSONObject> children,List<JSONObject> fatherRange) {
|
|
|
- Set<String> fatherCode= children.stream()
|
|
|
- .map(v->v.getString(String.valueOf(ParkKey.c_parent_code)))
|
|
|
+ // public void runWithOutLease(Collection<String> focusUpdateLdCode, Collection<String> focusUpdateLcCode, Collection<String> focusUpdateRoomCode) {
|
|
|
+// //拿强制加载数据
|
|
|
+// Collection<JSONObject> rooms = new HashSet<>(getRoomsWithCode(focusUpdateRoomCode, allRoom));
|
|
|
+// Collection<JSONObject> lcs = new HashSet<>(getRoomsWithCode(focusUpdateLcCode, allLc));
|
|
|
+// Collection<JSONObject> lds = new HashSet<>(getRoomsWithCode(focusUpdateLdCode, allLd));
|
|
|
+// //逐级寻子
|
|
|
+// //逐级寻父
|
|
|
+// lcs.addAll(findFathers(rooms,allLc));
|
|
|
+// lds.addAll(findFathers(lcs,allLd));
|
|
|
+// //统计,当然房间不参与这个统计,因为没有租赁信息
|
|
|
+// lcs.forEach(this::countParkByChild);
|
|
|
+// lds.forEach(this::countParkByChild);
|
|
|
+// //楼宇必须更新,这里不考虑多楼宇
|
|
|
+// countParkByChild(allLy.get(0));
|
|
|
+//
|
|
|
+// }
|
|
|
+ public void runWithOutLease() {
|
|
|
+ //统计,当然房间不参与这个统计,因为没有租赁信息和子级
|
|
|
+ allLd.forEach(this::countParkByChild);
|
|
|
+ allLc.forEach(this::countParkByChild);
|
|
|
+ allLy.forEach(this::countParkByChild);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JSONObject> findFathers(Collection<JSONObject> children, List<JSONObject> fatherRange) {
|
|
|
+ Set<String> fatherCode = children.stream()
|
|
|
+ .map(v -> v.getString(String.valueOf(ParkKey.c_parent_code)))
|
|
|
.collect(Collectors.toSet());
|
|
|
return fatherRange.stream()
|
|
|
- .filter(v->fatherCode.contains(v.getString(String.valueOf(ParkKey.c_park_code))))
|
|
|
+ .filter(v -> fatherCode.contains(v.getString(String.valueOf(ParkKey.c_park_code))))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 预计算单房间与相关租赁,会修改输入值,会自动统计变动对象
|
|
|
*
|
|
|
@@ -196,9 +232,9 @@ public class DataPreCounter {
|
|
|
}
|
|
|
|
|
|
//评估房间是否需要更新
|
|
|
- boolean shouldRoomUpdateFlag = shouldRoomUpdate(room,newWorkingLease);
|
|
|
- if(shouldRoomUpdateFlag){
|
|
|
- updateRoomLease(room,newWorkingLease);
|
|
|
+ boolean shouldRoomUpdateFlag = shouldRoomUpdate(room, newWorkingLease);
|
|
|
+ if (shouldRoomUpdateFlag) {
|
|
|
+ updateRoomLease(room, newWorkingLease);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -207,7 +243,7 @@ public class DataPreCounter {
|
|
|
|
|
|
|
|
|
private void updateRoomLease(JSONObject room, JSONObject lease) {
|
|
|
- if (lease == null||!checkLeaseWorking(lease)) {
|
|
|
+ if (lease == null || !checkLeaseWorking(lease)) {
|
|
|
//绑定企业信息
|
|
|
updateStringValue(room,
|
|
|
String.valueOf(ParkKey.c_zlqymc),
|
|
|
@@ -292,10 +328,11 @@ public class DataPreCounter {
|
|
|
return workingLease != lastWorkingLease;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private boolean shouldRoomUpdate(JSONObject room, JSONObject lease) {
|
|
|
//检查企业数据
|
|
|
- boolean isEnterpriseDataEqual = compareRoomAndLeaseByKey(room, lease,ParkKey.c_zlqydm,LeaseKey.c_enterprise_code);
|
|
|
- isEnterpriseDataEqual = isEnterpriseDataEqual && compareRoomAndLeaseByKey(room, lease,ParkKey.c_zlqymc,LeaseKey.c_enterprise_name);
|
|
|
+ boolean isEnterpriseDataEqual = compareRoomAndLeaseByKey(room, lease, ParkKey.c_zlqydm, LeaseKey.c_enterprise_code);
|
|
|
+ isEnterpriseDataEqual = isEnterpriseDataEqual && compareRoomAndLeaseByKey(room, lease, ParkKey.c_zlqymc, LeaseKey.c_enterprise_name);
|
|
|
|
|
|
//检查房间状态与lease匹配性
|
|
|
boolean roomUsing = !"1".equals(room.getString(String.valueOf(ParkKey.c_room_status)));
|
|
|
@@ -304,7 +341,7 @@ public class DataPreCounter {
|
|
|
return !(isEnterpriseDataEqual && isWorkingDataEqual);
|
|
|
}
|
|
|
|
|
|
- private static boolean compareRoomAndLeaseByKey(JSONObject room, JSONObject lease,ParkKey roomKey,LeaseKey leaseKey) {
|
|
|
+ private static boolean compareRoomAndLeaseByKey(JSONObject room, JSONObject lease, ParkKey roomKey, LeaseKey leaseKey) {
|
|
|
return Objects.equals(room.getString(String.valueOf(roomKey)), lease.getString(String.valueOf(leaseKey)));
|
|
|
}
|
|
|
|
|
|
@@ -422,7 +459,8 @@ public class DataPreCounter {
|
|
|
|
|
|
private void updateDoubleValue(JSONObject obj, String key, Double value, Set<String> uploadList) {
|
|
|
Double oldValue = obj.getDouble(key);
|
|
|
- if (!oldValue.equals(value)) {
|
|
|
+
|
|
|
+ if (!Objects.equals(oldValue, value)) {
|
|
|
obj.put(key, value);
|
|
|
uploadList.add(obj.getString("id"));
|
|
|
}
|