Commit 03c278e1 authored by yanzg's avatar yanzg

默认日期格式的支持

parent 68830845
...@@ -22,10 +22,9 @@ public class DataDaoVo<T> { ...@@ -22,10 +22,9 @@ public class DataDaoVo<T> {
* *
* @param hisitories 历史数据 * @param hisitories 历史数据
* @param keyFunc  获取主键函数 * @param keyFunc  获取主键函数
* @param <T>
* @return * @return
*/ */
private static <T> Map<String, T> getMapHistory(List<T> hisitories, DataDaoKey<T> keyFunc) { private Map<String, T> getMapHistory(List<T> hisitories, DataDaoKey<T> keyFunc) {
// 定义缓存集合 // 定义缓存集合
Map<String, T> mapHistory = new HashMap<>(10); Map<String, T> mapHistory = new HashMap<>(10);
// 历史数据处理 // 历史数据处理
...@@ -44,33 +43,31 @@ public class DataDaoVo<T> { ...@@ -44,33 +43,31 @@ public class DataDaoVo<T> {
* @param mapHistory 历史数据映射 * @param mapHistory 历史数据映射
* @param nows  当前数据 * @param nows  当前数据
* @param keyFunc  获取主键函数 * @param keyFunc  获取主键函数
* @param <T>
* @return * @return
*/ */
private static <T> DataDaoVo<T> getResult(Map<String, T> mapHistory, List<T> nows, DataDaoKey<T> keyFunc) { private void addResult(Map<String, T> mapHistory, List<T> nows, DataDaoKey<T> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>();
// 返回集 // 返回集
if (nows != null) { if (nows != null) {
for (T now : nows) { for (T now : nows) {
String key = keyFunc.getKey(now); String key = keyFunc.getKey(now);
T his = mapHistory.get(key); T his = mapHistory.get(key);
if (his == null) { if (his == null) {
res.creates.add(now); this.creates.add(now);
res.mapNow.put(key, now); this.mapNow.put(key, now);
} else { } else {
mapHistory.remove(key); mapHistory.remove(key);
boolean isChange = keyFunc.set(his, now); boolean isChange = keyFunc.set(his, now);
if (isChange) { if (isChange) {
res.updates.add(his); this.updates.add(his);
} }
res.mapNow.put(key, his); this.mapNow.put(key, his);
} }
} }
} }
res.removes.addAll(mapHistory.values()); this.removes.addAll(mapHistory.values());
return res;
} }
/** /**
* 初始话对象 * 初始话对象
* *
...@@ -78,10 +75,9 @@ public class DataDaoVo<T> { ...@@ -78,10 +75,9 @@ public class DataDaoVo<T> {
* @param nows * @param nows
* @param keyFunc * @param keyFunc
*/ */
public static <T> DataDaoVo<T> init(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) { public void add(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) {
Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc); Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc);
DataDaoVo<T> res = getResult(mapHistory, nows, keyFunc); addResult(mapHistory, nows, keyFunc);
return res;
} }
...@@ -92,7 +88,7 @@ public class DataDaoVo<T> { ...@@ -92,7 +88,7 @@ public class DataDaoVo<T> {
* @param nows * @param nows
* @param keyFunc * @param keyFunc
*/ */
public static <T, M> DataDaoVo<T> init(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) { public <M> void add(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) {
Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc); Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc);
List<T> toNows = new ArrayList<>(10); List<T> toNows = new ArrayList<>(10);
if (nows != null) { if (nows != null) {
...@@ -101,7 +97,33 @@ public class DataDaoVo<T> { ...@@ -101,7 +97,33 @@ public class DataDaoVo<T> {
toNows.add(t); toNows.add(t);
} }
} }
DataDaoVo<T> res = getResult(mapHistory, toNows, keyFunc); addResult(mapHistory, toNows, keyFunc);
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public static <T> DataDaoVo<T> init(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>();
res.add(hisitories, nows, keyFunc);
return res;
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public static <T, M> DataDaoVo<T> init(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>();
res.add(hisitories, nows, keyFunc);
return res; return res;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment