|
|
@@ -1,18 +1,26 @@
|
|
|
package com.uas.search.console.util;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.FileReader;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.PrintWriter;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.search.console.model.BrandSimpleInfo;
|
|
|
import com.uas.search.console.model.ComponentSimpleInfo;
|
|
|
+import com.uas.search.console.model.KindSimpleInfo;
|
|
|
import com.uas.search.console.model.PropertyValueSimpleInfo;
|
|
|
|
|
|
/**
|
|
|
@@ -27,7 +35,25 @@ public class MergeComponentData {
|
|
|
public static final int SINGLE_FILE_MAX_SIZE = 100000;
|
|
|
|
|
|
// 器件和属性值两个文本文件的路径
|
|
|
- private static final String DATA_DIR = "C:\\Users\\sunyj-pc\\Desktop\\data\\prod";
|
|
|
+ private static final String DATA_DIR = "C:\\Users\\sunyj-pc\\Desktop\\temp\\data\\test";
|
|
|
+
|
|
|
+ private static Map<Long, KindSimpleInfo> kinds;
|
|
|
+ private static Map<Long, BrandSimpleInfo> brands ;
|
|
|
+
|
|
|
+ static{
|
|
|
+ try {
|
|
|
+ File kindFile=new File(DATA_DIR+"/kind.json");
|
|
|
+ String json = readAsString(kindFile);
|
|
|
+ kinds = parseKinds(json);
|
|
|
+
|
|
|
+ File brandFile=new File(DATA_DIR+"/brand.json");
|
|
|
+ String json2 = readAsString(brandFile);
|
|
|
+ brands = parseBrands(json2);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 将从本地文件读取的一行字符串数据解析为器件对象
|
|
|
@@ -36,29 +62,76 @@ public class MergeComponentData {
|
|
|
* 格式为"CMP_ID" "CMP_BRID" "CMP_CODE" "CMP_KIID" "CMP_RESERVE"
|
|
|
* "CMP_SAMPLEQTY" "CMP_ORIGINALQTY" "CMP_UUID" "CMP_INASTOCKQTY"
|
|
|
* @return
|
|
|
+ * @throws IOException
|
|
|
+ * @throws FileNotFoundException
|
|
|
*/
|
|
|
- private static ComponentSimpleInfo parseComponent(String data) {
|
|
|
+ private static ComponentSimpleInfo parseComponent(String data) throws FileNotFoundException, IOException {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
ComponentSimpleInfo component = new ComponentSimpleInfo();
|
|
|
String[] strs = data.split("\t");
|
|
|
component.setId(Long.parseLong(strs[0]));
|
|
|
- component.setBrandid(Long.parseLong(strs[1]));
|
|
|
+ long brandId = Long.parseLong(strs[1]);
|
|
|
+ component.setBrand(brands.get(brandId));
|
|
|
component.setCode(strs[2].substring(1, strs[2].length() - 1));
|
|
|
- if (!StringUtils.isEmpty(strs[3])) {
|
|
|
- component.setReserve(Double.valueOf(strs[3]));
|
|
|
- }
|
|
|
+ Long kindId=Long.parseLong(strs[3]);
|
|
|
+ component.setKind(kinds.get(kindId));
|
|
|
if (!StringUtils.isEmpty(strs[4])) {
|
|
|
- component.setSampleQty(Double.valueOf(strs[4]));
|
|
|
+ component.setReserve(Double.valueOf(strs[4]));
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(strs[5])) {
|
|
|
- component.setOriginalQty(Double.valueOf(strs[5]));
|
|
|
+ component.setSampleQty(Double.valueOf(strs[5]));
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(strs[6])) {
|
|
|
- component.setInactionStockQty(Double.valueOf(strs[6]));
|
|
|
+ component.setOriginalQty(Double.valueOf(strs[6]));
|
|
|
+ }
|
|
|
+ component.setUuid(strs[7].substring(1, strs[7].length() - 1));
|
|
|
+ if (strs.length>8 && !StringUtils.isEmpty(strs[8])) {
|
|
|
+ component.setInactionStockQty(Double.valueOf(strs[8]));
|
|
|
}
|
|
|
- component.setKindid(Long.parseLong(strs[7]));
|
|
|
- component.setUuid(strs[8].substring(1, strs[8].length() - 1));
|
|
|
return component;
|
|
|
}
|
|
|
+
|
|
|
+ private static Map<Long, KindSimpleInfo> parseKinds(String json){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("items");
|
|
|
+ Map<Long, KindSimpleInfo> map=new HashMap<>();
|
|
|
+ for(Object object :jsonArray){
|
|
|
+ JSONObject obj=(JSONObject) object;
|
|
|
+ Long id = obj.getLong("ki_id");
|
|
|
+ String name = obj.getString("ki_name");
|
|
|
+ Short level = obj.getShort("ki_level");
|
|
|
+ Short isLeaf = obj.getShort("ki_isleaf");
|
|
|
+ KindSimpleInfo kind=new KindSimpleInfo();
|
|
|
+ kind.setId(id);
|
|
|
+ kind.setNameCn(name);
|
|
|
+ kind.setLevel(level);
|
|
|
+ kind.setIsLeaf(isLeaf);
|
|
|
+ map.put(id, kind);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<Long, BrandSimpleInfo> parseBrands(String json){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray("items");
|
|
|
+ Map<Long, BrandSimpleInfo> map=new HashMap<>();
|
|
|
+ for(Object object :jsonArray){
|
|
|
+ JSONObject obj=(JSONObject) object;
|
|
|
+ Long id = obj.getLong("br_id");
|
|
|
+ String uuid = obj.getString("br_uuid");
|
|
|
+ String nameCn = obj.getString("br_name_cn");
|
|
|
+ String nameEn = obj.getString("br_name_en");
|
|
|
+ BrandSimpleInfo brand=new BrandSimpleInfo();
|
|
|
+ brand.setId(id);
|
|
|
+ brand.setUuid(uuid);
|
|
|
+ brand.setNameCn(nameCn);
|
|
|
+ brand.setNameEn(nameEn);
|
|
|
+ map.put(id, brand);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 将从本地文件读取的一行字符串数据解析为属性值对象
|
|
|
@@ -76,6 +149,57 @@ public class MergeComponentData {
|
|
|
propertyValue.setValue(strs[2].substring(1, strs[2].length() - 1));
|
|
|
return propertyValue;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取文件内容输出字符串
|
|
|
+ *
|
|
|
+ * @param file
|
|
|
+ * 文件
|
|
|
+ * @return 读取的内容
|
|
|
+ */
|
|
|
+ public static String readAsString( File file) throws FileNotFoundException, IOException {
|
|
|
+ if (!file.exists() || file.isDirectory()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ FileInputStream stream = new FileInputStream(file);
|
|
|
+ return readAsString(stream);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取输入流输出字符串
|
|
|
+ *
|
|
|
+ * @param stream
|
|
|
+ * 将要读的输入流
|
|
|
+ * @return 读取的内容
|
|
|
+ */
|
|
|
+ public static String readAsString( InputStream stream)
|
|
|
+ throws FileNotFoundException, IOException {
|
|
|
+ // 以UTF-8编码方式读取文件
|
|
|
+ String result = new String(readStream(stream), "UTF-8");
|
|
|
+ stream.close();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Read the supplied InputStream and return as a byte array.
|
|
|
+ *
|
|
|
+ * @param stream
|
|
|
+ * The stream to read.
|
|
|
+ * @return byte array containing the Stream data.
|
|
|
+ * @throws IOException
|
|
|
+ * Exception reading from the stream.
|
|
|
+ */
|
|
|
+ public static byte[] readStream( InputStream stream) throws IOException {
|
|
|
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
|
|
|
+ byte[] byteBuf = new byte[1024];
|
|
|
+ int readCount = 0;
|
|
|
+
|
|
|
+ while ((readCount = stream.read(byteBuf)) != -1) {
|
|
|
+ bytesOut.write(byteBuf, 0, readCount);
|
|
|
+ }
|
|
|
+ stream.close();
|
|
|
+ return bytesOut.toByteArray();
|
|
|
+ }
|
|
|
|
|
|
public static void merge() {
|
|
|
BufferedReader componentReader = null;
|
|
|
@@ -169,9 +293,8 @@ public class MergeComponentData {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // public static void main(String[] args) {
|
|
|
- // merge();
|
|
|
- // // readData();
|
|
|
- // }
|
|
|
+// public static void main(String[] args) {
|
|
|
+// merge();
|
|
|
+// }
|
|
|
|
|
|
}
|