Commit 59ce0ba1 authored by yanzg's avatar yanzg

接口文档的支持

parent 829ef31e
package com.yanzuoguang.util.vo; package com.yanzuoguang.util.vo;
import java.util.Map;
/** /**
* 获取关键字 * 获取关键字
* *
...@@ -10,8 +12,9 @@ public interface DataDaoKeyConvert<T, M> extends DataDaoKey<T> { ...@@ -10,8 +12,9 @@ public interface DataDaoKeyConvert<T, M> extends DataDaoKey<T> {
/** /**
* 获取关键字 * 获取关键字
* *
* @param from 来源对象 * @param mapHistory 映射的历史数据
* @param from 来源对象
* @return * @return
*/ */
T convert(M from); T convert(Map<String, T> mapHistory, M from);
} }
...@@ -18,13 +18,14 @@ public class DataDaoVo<T> { ...@@ -18,13 +18,14 @@ public class DataDaoVo<T> {
private Map<String, T> mapNow = new HashMap<>(); private Map<String, T> mapNow = new HashMap<>();
/** /**
* 初始话对象 * 将历史数据映射为HashMap
* *
* @param hisitories * @param hisitories 历史数据
* @param nows * @param keyFunc  获取主键函数
* @param keyFunc * @param <T>
* @return
*/ */
public static <T> DataDaoVo<T> init(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) { private static <T> Map<String, T> getMapHistory(List<T> hisitories, DataDaoKey<T> keyFunc) {
// 定义缓存集合 // 定义缓存集合
Map<String, T> mapHistory = new HashMap<>(10); Map<String, T> mapHistory = new HashMap<>(10);
// 历史数据处理 // 历史数据处理
...@@ -34,6 +35,19 @@ public class DataDaoVo<T> { ...@@ -34,6 +35,19 @@ public class DataDaoVo<T> {
mapHistory.put(key, his); mapHistory.put(key, his);
} }
} }
return mapHistory;
}
/**
* 获取结果
*
* @param mapHistory 历史数据映射
* @param nows  当前数据
* @param keyFunc  获取主键函数
* @param <T>
* @return
*/
private static <T> DataDaoVo<T> getResult(Map<String, T> mapHistory, List<T> nows, DataDaoKey<T> keyFunc) {
DataDaoVo<T> res = new DataDaoVo<T>(); DataDaoVo<T> res = new DataDaoVo<T>();
// 返回集 // 返回集
if (nows != null) { if (nows != null) {
...@@ -52,7 +66,19 @@ public class DataDaoVo<T> { ...@@ -52,7 +66,19 @@ public class DataDaoVo<T> {
} }
} }
res.removes.addAll(mapHistory.values()); res.removes.addAll(mapHistory.values());
return res;
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public static <T> DataDaoVo<T> init(List<T> hisitories, List<T> nows, DataDaoKey<T> keyFunc) {
Map<String, T> mapHistory = getMapHistory(hisitories, keyFunc);
DataDaoVo<T> res = getResult(mapHistory, nows, keyFunc);
return res; return res;
} }
...@@ -65,14 +91,16 @@ public class DataDaoVo<T> { ...@@ -65,14 +91,16 @@ public class DataDaoVo<T> {
* @param keyFunc * @param keyFunc
*/ */
public static <T, M> DataDaoVo<T> init(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> keyFunc) { public static <T, M> DataDaoVo<T> init(List<T> hisitories, List<M> nows, DataDaoKeyConvert<T, M> 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) {
for (M m : nows) { for (M m : nows) {
T t = keyFunc.convert(m); T t = keyFunc.convert(mapHistory, m);
toNows.add(t); toNows.add(t);
} }
} }
return init(hisitories, toNows, keyFunc); DataDaoVo<T> res = getResult(mapHistory, toNows, keyFunc);
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