|
|
@@ -3,6 +3,8 @@ package com.uas.search.console.b2b.service.impl;
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.PrintWriter;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@@ -16,13 +18,13 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.search.b2b.model.SPage;
|
|
|
import com.uas.search.b2b.service.SearchService.Table_name;
|
|
|
import com.uas.search.console.b2b.core.util.ContextUtils;
|
|
|
-import com.uas.search.console.b2b.model.PurchaseInquiryMouldSimpleInfo;
|
|
|
+import com.uas.search.console.b2b.jms.AQListener;
|
|
|
import com.uas.search.console.b2b.schedule.model.DailyTaskInformation;
|
|
|
import com.uas.search.console.b2b.schedule.model.DailyTaskLog;
|
|
|
import com.uas.search.console.b2b.schedule.service.DailyTaskService;
|
|
|
import com.uas.search.console.b2b.service.IndexService;
|
|
|
import com.uas.search.console.b2b.service.InnerSearchService;
|
|
|
-import com.uas.search.console.b2b.service.PurchaseInquiryMouldSimpleInfoService;
|
|
|
+import com.uas.search.console.b2b.service.UpdateVirtualColumnService;
|
|
|
import com.uas.search.console.b2b.util.ClassAndTableNameUtils;
|
|
|
import com.uas.search.console.b2b.util.SearchUtils;
|
|
|
|
|
|
@@ -31,7 +33,7 @@ import com.uas.search.console.b2b.util.SearchUtils;
|
|
|
* @since 2016年12月12日 下午5:40:42
|
|
|
*/
|
|
|
@Service
|
|
|
-public class PurchaseInquiryMouldSimpleInfoServiceImpl implements PurchaseInquiryMouldSimpleInfoService {
|
|
|
+public class UpdateVirtualColumnServiceImpl implements UpdateVirtualColumnService {
|
|
|
|
|
|
/**
|
|
|
* 默认的页码
|
|
|
@@ -49,21 +51,30 @@ public class PurchaseInquiryMouldSimpleInfoServiceImpl implements PurchaseInquir
|
|
|
@Autowired
|
|
|
private IndexService indexService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AQListener aqListener;
|
|
|
+
|
|
|
private InnerSearchService innerSearchService = ContextUtils.getApplicationContext().getBean("searchServiceImpl",
|
|
|
InnerSearchService.class);
|
|
|
|
|
|
- private Logger logger = LoggerFactory.getLogger(PurchaseInquiryMouldSimpleInfoServiceImpl.class);
|
|
|
+ private Logger logger = LoggerFactory.getLogger(UpdateVirtualColumnServiceImpl.class);
|
|
|
|
|
|
- @Override
|
|
|
- public void updateOverdue() {
|
|
|
+ /**
|
|
|
+ * 更新指定实体类的overdue虚拟列的索引
|
|
|
+ *
|
|
|
+ * @param <T>
|
|
|
+ *
|
|
|
+ * @param clazz
|
|
|
+ * 实体类
|
|
|
+ */
|
|
|
+ private <T> void updateOverdue(Class<T> clazz) {
|
|
|
// 不能边更新索引边分页获取索引中的数据,因为索引更新后,分页顺序可能也会变化,
|
|
|
// 所以要先把数据保存到本地,等待全部获取之后重建索引
|
|
|
Long startTime = new Date().getTime();
|
|
|
- Table_name tableName = ClassAndTableNameUtils.toTableName(PurchaseInquiryMouldSimpleInfo.class);
|
|
|
+ Table_name tableName = ClassAndTableNameUtils.toTableName(clazz);
|
|
|
|
|
|
int page = PAGE_INDEX;
|
|
|
- SPage<PurchaseInquiryMouldSimpleInfo> sPage = innerSearchService
|
|
|
- .getAllObjects(PurchaseInquiryMouldSimpleInfo.class, page, PAGE_SIZE);
|
|
|
+ SPage<T> sPage = innerSearchService.getAllObjects(clazz, page, PAGE_SIZE);
|
|
|
|
|
|
// 数据库中数据的总数目
|
|
|
long totalElements = sPage.getTotalElement();
|
|
|
@@ -86,10 +97,12 @@ public class PurchaseInquiryMouldSimpleInfoServiceImpl implements PurchaseInquir
|
|
|
fileIndex++;
|
|
|
printWriter = new PrintWriter(SearchUtils.getDataPath(tableName) + "/" + fileIndex + ".txt");
|
|
|
}
|
|
|
- List<PurchaseInquiryMouldSimpleInfo> content = sPage.getContent();
|
|
|
- for (PurchaseInquiryMouldSimpleInfo purchaseInquiryMould : content) {
|
|
|
- purchaseInquiryMould.setOverdue(purchaseInquiryMould.getOverdue());
|
|
|
- printWriter.println(JSONObject.toJSONString(purchaseInquiryMould));
|
|
|
+ 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));
|
|
|
+ printWriter.println(JSONObject.toJSONString(element));
|
|
|
count++;
|
|
|
}
|
|
|
logger.info(String.format(tableName.value() + "...................%.2f%%",
|
|
|
@@ -98,25 +111,29 @@ public class PurchaseInquiryMouldSimpleInfoServiceImpl implements PurchaseInquir
|
|
|
if (++page > sPage.getTotalPage()) {
|
|
|
break;
|
|
|
}
|
|
|
- sPage = innerSearchService.getAllObjects(PurchaseInquiryMouldSimpleInfo.class, page, PAGE_SIZE);
|
|
|
+ sPage = innerSearchService.getAllObjects(clazz, page, PAGE_SIZE);
|
|
|
}
|
|
|
printWriter.flush();
|
|
|
printWriter.close();
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
+ } catch (FileNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException
|
|
|
+ | IllegalArgumentException | InvocationTargetException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
Long endTime = new Date().getTime();
|
|
|
logger.info(String.format("修改数据%s条,耗时%.2fs\n ", totalElements, (endTime - startTime) / 1000.0));
|
|
|
indexService.createIndexs(Arrays.asList(tableName), true);
|
|
|
+ aqListener.start(null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public DailyTaskInformation startUpdateOverdueDailyTask(Integer hour, Integer minute, Integer second) {
|
|
|
+ public <T> DailyTaskInformation createUpdateOverdueDailyTask(final Class<T> clazz, Integer hour, Integer minute,
|
|
|
+ Integer second) {
|
|
|
if (hour == null || minute == null || second == null) {
|
|
|
throw new NullPointerException();
|
|
|
}
|
|
|
final DailyTaskInformation dailyTaskInformation = new DailyTaskInformation();
|
|
|
- dailyTaskInformation.setTitle("更新虚拟列索引:模具询价单");
|
|
|
+ dailyTaskInformation
|
|
|
+ .setTitle("更新虚拟列索引overdue:" + ClassAndTableNameUtils.toTableName(clazz).value().toLowerCase());
|
|
|
dailyTaskInformation.setHour(hour);
|
|
|
dailyTaskInformation.setMinute(minute);
|
|
|
dailyTaskInformation.setSecond(second);
|
|
|
@@ -124,7 +141,7 @@ public class PurchaseInquiryMouldSimpleInfoServiceImpl implements PurchaseInquir
|
|
|
@Override
|
|
|
public void run() {
|
|
|
logger.info("Daily Task run...");
|
|
|
- updateOverdue();
|
|
|
+ updateOverdue(clazz);
|
|
|
DailyTaskLog dailyTaskLog = new DailyTaskLog(dailyTaskInformation, new Date(), "success");
|
|
|
dailyTaskService.saveLog(dailyTaskLog);
|
|
|
}
|
|
|
@@ -133,4 +150,9 @@ public class PurchaseInquiryMouldSimpleInfoServiceImpl implements PurchaseInquir
|
|
|
return dailyTaskInformation;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String start() {
|
|
|
+ return dailyTaskService.start();
|
|
|
+ }
|
|
|
+
|
|
|
}
|