|
|
@@ -18,7 +18,6 @@ import com.uas.search.support.DownloadHelper;
|
|
|
import com.uas.search.support.DownloadService;
|
|
|
import com.uas.search.support.IndexSearcherManager;
|
|
|
import com.uas.search.support.IndexWriterManager;
|
|
|
-import com.uas.search.util.FileUtils;
|
|
|
import com.uas.search.util.ObjectToDocumentUtils;
|
|
|
import com.uas.search.util.SearchUtils;
|
|
|
import org.apache.lucene.document.Document;
|
|
|
@@ -420,62 +419,6 @@ public class IndexServiceImpl implements IndexService {
|
|
|
return multiDownloadData(COMPONENT_TABLE_NAME,threads,startFileIndex,endFileIndex);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Long convertGoodsFromComponent() {
|
|
|
- Long startTime = new Date().getTime();
|
|
|
- Long size = 0L;
|
|
|
- logger.info("转换批次... ");
|
|
|
- BufferedReader bufferedReader = null;
|
|
|
- try {
|
|
|
- // 从本地路径读取器件数据
|
|
|
- String componentDataPath = SearchUtils.getDataPath(COMPONENT_TABLE_NAME);
|
|
|
- String goodsDataPath = SearchUtils.getDataPath(SearchConstants.GOODS_TABLE_NAME);
|
|
|
- File[] files = new File(componentDataPath).listFiles();
|
|
|
- if (files == null || files.length == 0) {
|
|
|
- logger.info("转换批次失败,原因:器件数据文件不存在!");
|
|
|
- return 0L;
|
|
|
- }
|
|
|
- FileUtils.deleteSubFiles(new File(goodsDataPath));
|
|
|
- int fileIndex = 1;
|
|
|
- for (File file : files) {
|
|
|
- logger.info("读取器件文件: " + file.getName());
|
|
|
- bufferedReader = new BufferedReader(new FileReader(file));
|
|
|
- String goodsFileName = String.format("%010d", fileIndex) + ".txt";
|
|
|
- PrintWriter printWriter = new PrintWriter(goodsDataPath + "/" + goodsFileName);
|
|
|
- String line;
|
|
|
- while (!StringUtils.isEmpty(line = bufferedReader.readLine())) {
|
|
|
- Component component;
|
|
|
- try {
|
|
|
- component = JSONObject.parseObject(line, Component.class);
|
|
|
- } catch (JSONException e) {
|
|
|
- throw new IllegalArgumentException(line, e);
|
|
|
- }
|
|
|
- // 器件作为主体,得到批次
|
|
|
- printWriter.println(JSONObject.toJSONString(new Goods(null, null, component, null)));
|
|
|
- size++;
|
|
|
- }
|
|
|
- logger.info(goodsFileName + " - Converted..................." + size);
|
|
|
- printWriter.flush();
|
|
|
- printWriter.close();
|
|
|
- fileIndex++;
|
|
|
- bufferedReader.close();
|
|
|
- }
|
|
|
- long endStartTime = new Date().getTime();
|
|
|
- logger.info(String.format("转换完成,耗时%.2fs\n ", (endStartTime - startTime) / 1000.0));
|
|
|
- return endStartTime - startTime;
|
|
|
- } catch (Throwable e) {
|
|
|
- throw new IllegalStateException("批次转换失败", e);
|
|
|
- }finally{
|
|
|
- if(bufferedReader!=null){
|
|
|
- try {
|
|
|
- bufferedReader.close();
|
|
|
- } catch (IOException e) {
|
|
|
- throw new IllegalStateException("批次转换失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public long multiDownloadGoods(Integer threads, Integer startFileIndex, Integer endFileIndex) {
|
|
|
return multiDownloadData(GOODS_TABLE_NAME,threads,startFileIndex,endFileIndex);
|