|
|
@@ -8,11 +8,15 @@ import java.lang.reflect.Method;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.search.b2b.model.SPage;
|
|
|
@@ -60,14 +64,16 @@ public class UpdateVirtualColumnServiceImpl implements UpdateVirtualColumnServic
|
|
|
private Logger logger = LoggerFactory.getLogger(UpdateVirtualColumnServiceImpl.class);
|
|
|
|
|
|
/**
|
|
|
- * 更新指定实体类的overdue虚拟列的索引
|
|
|
+ * 更新指定实体类的虚拟列的索引
|
|
|
*
|
|
|
* @param <T>
|
|
|
*
|
|
|
* @param clazz
|
|
|
* 实体类
|
|
|
+ * @param fields
|
|
|
+ * 需更新的虚拟列,键值对(虚拟列名称:类型,实体中必须存在对应的get/set方法)
|
|
|
*/
|
|
|
- private <T> void updateOverdue(Class<T> clazz) {
|
|
|
+ private <T> void updateVirtualColumn(Class<T> clazz, Map<String, Class<?>> fields) {
|
|
|
// 不能边更新索引边分页获取索引中的数据,因为索引更新后,分页顺序可能也会变化,
|
|
|
// 所以要先把数据保存到本地,等待全部获取之后重建索引
|
|
|
Long startTime = new Date().getTime();
|
|
|
@@ -99,9 +105,16 @@ public class UpdateVirtualColumnServiceImpl implements UpdateVirtualColumnServic
|
|
|
}
|
|
|
List<T> content = sPage.getContent();
|
|
|
for (T element : content) {
|
|
|
- Method getOverdueMethod = clazz.getMethod("getOverdue");
|
|
|
- Method setOverdueMethod = clazz.getMethod("setOverdue", Short.class);
|
|
|
- setOverdueMethod.invoke(element, getOverdueMethod.invoke(element));
|
|
|
+ Set<Entry<String, Class<?>>> entrySet = fields.entrySet();
|
|
|
+ for (Entry<String, Class<?>> entry : entrySet) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Class<?> type = entry.getValue();
|
|
|
+ // 首字母大写
|
|
|
+ key = key.substring(0, 1).toUpperCase() + key.substring(1);
|
|
|
+ Method getMethod = clazz.getMethod("get" + key);
|
|
|
+ Method setMethod = clazz.getMethod("set" + key, type);
|
|
|
+ setMethod.invoke(element, getMethod.invoke(element));
|
|
|
+ }
|
|
|
printWriter.println(JSONObject.toJSONString(element));
|
|
|
count++;
|
|
|
}
|
|
|
@@ -128,17 +141,20 @@ public class UpdateVirtualColumnServiceImpl implements UpdateVirtualColumnServic
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public <T> DailyTaskInformation newUpdateOverdueDailyTask(final Class<T> clazz, Integer hour, Integer minute,
|
|
|
- Integer second) {
|
|
|
+ public <T> DailyTaskInformation newDailyTask(final Class<T> clazz, final Map<String, Class<?>> fields, Integer hour,
|
|
|
+ Integer minute, Integer second) {
|
|
|
if (hour == null || minute == null || second == null) {
|
|
|
throw new NullPointerException();
|
|
|
}
|
|
|
+ if (CollectionUtils.isEmpty(fields)) {
|
|
|
+ throw new IllegalArgumentException("fields");
|
|
|
+ }
|
|
|
|
|
|
- String title = "更新虚拟列索引overdue:" + ClassAndTableNameUtils.toTableName(clazz).value().toLowerCase();
|
|
|
+ String title = "更新虚拟列索引" + fields + ":" + ClassAndTableNameUtils.toTableName(clazz).value().toLowerCase();
|
|
|
Executable command = new Executable() {
|
|
|
@Override
|
|
|
public String execute() {
|
|
|
- updateOverdue(clazz);
|
|
|
+ updateVirtualColumn(clazz, fields);
|
|
|
return "success";
|
|
|
}
|
|
|
};
|