|
@@ -25,338 +25,339 @@ import java.util.UUID;
|
|
|
@Slf4j
|
|
|
public class UpdateInfoCodeTag {
|
|
|
|
|
|
- private String basepath = "/Users/devsaga/trans";
|
|
|
-
|
|
|
- private String outPath = "/Users/devsaga/trans/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
|
|
|
-
|
|
|
- @Test
|
|
|
- public void test1() throws IOException {
|
|
|
- String majorCode = "OT";
|
|
|
- String file = basepath + "/85-传感器.xlsx";
|
|
|
-
|
|
|
- FileInputStream inputStream = new FileInputStream(file);
|
|
|
- Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
-
|
|
|
- int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
-
|
|
|
- List<FuncidDefModel> data = new LinkedList<>();
|
|
|
-
|
|
|
- for (int i = 0; i < numberOfSheets; i++) {
|
|
|
- Sheet sheet = workbook.getSheetAt(i);
|
|
|
- String sheetName = sheet.getSheetName();
|
|
|
- System.out.println(sheetName);
|
|
|
-
|
|
|
- String classCode = majorCode + sheetName.substring(0, 4);
|
|
|
-
|
|
|
-
|
|
|
- int startRowNum = 2;
|
|
|
- int lastRowNum = sheet.getLastRowNum();
|
|
|
- CacheModel cache = new CacheModel();
|
|
|
- for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
|
|
|
- Row row = sheet.getRow(rowIndex);
|
|
|
- if (row == null) {
|
|
|
- log.info("file: {}, sheet: {}, row[{}] is null", null, sheetName, rowIndex);
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
|
|
|
- CacheModel target = new CacheModel();
|
|
|
- target.classCode = classCode;
|
|
|
- target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
|
|
|
- target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
|
|
|
- target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
|
|
|
- target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
|
|
|
- target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
|
|
|
- target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
|
|
|
- target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
|
|
|
- target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
|
|
|
- target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
|
|
|
- target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
|
|
|
-
|
|
|
- if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (FuncidUtils.isBase(target.origCode)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // firstTag不为空
|
|
|
- if (target.firstTag != null) {
|
|
|
- cache.firstTag = target.firstTag;
|
|
|
- cache.secondTag = null;
|
|
|
- } else {
|
|
|
- target.firstTag = cache.firstTag;
|
|
|
- }
|
|
|
-
|
|
|
- // secondTag
|
|
|
- if (target.secondTag != null) {
|
|
|
- cache.secondTag = target.secondTag;
|
|
|
- } else {
|
|
|
- target.secondTag = cache.secondTag;
|
|
|
- }
|
|
|
- FuncidDefModel funcidDefModel = toFuncidDefModel(target);
|
|
|
- if (funcidDefModel == null) {
|
|
|
- log.info("file: {}, sheet: {}, row: {} data type [{}] error", null, sheetName, rowIndex, target.origDataType);
|
|
|
- } else {
|
|
|
- data.add(funcidDefModel);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- List<String> sqls = new LinkedList<>();
|
|
|
- for (FuncidDefModel funcid : data) {
|
|
|
- //System.out.println(funcid.getClassCode() + "\t" + funcid.getFirstTag() + "\t" + funcid.getSecondTag() + "\t" + funcid.getOrigCode() + "\t" + funcid.getName());
|
|
|
- // update rwd_def_funcid set first_tag = '', second_tag = '' where class_code = '' and orig_code = '';
|
|
|
- StringBuilder sql = new StringBuilder();
|
|
|
- sql.append("update rwd_def_funcid set first_tag = ")
|
|
|
- .append(funcid.getFirstTag() == null ? null : "'" + funcid.getFirstTag().trim() + "'")
|
|
|
- .append(", ")
|
|
|
- .append("second_tag = ")
|
|
|
- .append(funcid.getSecondTag() == null ? null : "'" + funcid.getSecondTag().trim() + "'")
|
|
|
- .append(" where class_code = '").append(funcid.getClassCode()).append("'")
|
|
|
- .append(" and orig_code = '").append(funcid.getOrigCode()).append("';")
|
|
|
- ;
|
|
|
-
|
|
|
- sqls.add(sql.toString());
|
|
|
- }
|
|
|
-
|
|
|
- for (String sql : sqls) {
|
|
|
- System.out.println(sql);
|
|
|
- }
|
|
|
-
|
|
|
- workbook.close();
|
|
|
- inputStream.close();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void importFuncidDef() throws IOException {
|
|
|
- List<FuncidDefModel> funcids = new LinkedList<>();
|
|
|
- importEquipment(funcids);
|
|
|
-
|
|
|
- FileOutputStream fos = new FileOutputStream(outPath);
|
|
|
- PrintWriter writer = new PrintWriter(new BufferedOutputStream(fos));
|
|
|
- writer.println("commit;");
|
|
|
- funcids.forEach(item -> {
|
|
|
+ private String basepath = "/Users/devsaga/trans";
|
|
|
+
|
|
|
+ private String outPath = "/Users/devsaga/trans/funcid-" + DateUtils.format(new Date()) + ".dml.sql";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test1() throws IOException {
|
|
|
+ String majorCode = "OT";
|
|
|
+ String file = basepath + "/85-传感器.xlsx";
|
|
|
+
|
|
|
+ FileInputStream inputStream = new FileInputStream(file);
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+
|
|
|
+ int numberOfSheets = workbook.getNumberOfSheets();
|
|
|
+
|
|
|
+ List<FuncidDefModel> data = new LinkedList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < numberOfSheets; i++) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(i);
|
|
|
+ String sheetName = sheet.getSheetName();
|
|
|
+ System.out.println(sheetName);
|
|
|
+
|
|
|
+ String classCode = majorCode + sheetName.substring(0, 4);
|
|
|
+
|
|
|
+
|
|
|
+ int startRowNum = 2;
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ CacheModel cache = new CacheModel();
|
|
|
+ for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ log.info("file: {}, sheet: {}, row[{}] is null", null, sheetName, rowIndex);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
|
|
|
+ CacheModel target = new CacheModel();
|
|
|
+ target.classCode = classCode;
|
|
|
+ target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
|
|
|
+ target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
|
|
|
+ target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
|
|
|
+ target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
|
|
|
+ target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
|
|
|
+ target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
|
|
|
+ target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
|
|
|
+ target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
|
|
|
+ target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
|
|
|
+ target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
|
|
|
+
|
|
|
+ if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (FuncidUtils.isBase(target.origCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // firstTag不为空
|
|
|
+ if (target.firstTag != null) {
|
|
|
+ cache.firstTag = target.firstTag;
|
|
|
+ cache.secondTag = null;
|
|
|
+ } else {
|
|
|
+ target.firstTag = cache.firstTag;
|
|
|
+ }
|
|
|
+
|
|
|
+ // secondTag
|
|
|
+ if (target.secondTag != null) {
|
|
|
+ cache.secondTag = target.secondTag;
|
|
|
+ } else {
|
|
|
+ target.secondTag = cache.secondTag;
|
|
|
+ }
|
|
|
+ FuncidDefModel funcidDefModel = toFuncidDefModel(target);
|
|
|
+ if (funcidDefModel == null) {
|
|
|
+ log.info("file: {}, sheet: {}, row: {} data type [{}] error", null, sheetName, rowIndex, target.origDataType);
|
|
|
+ } else {
|
|
|
+ data.add(funcidDefModel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> sqls = new LinkedList<>();
|
|
|
+ for (FuncidDefModel funcid : data) {
|
|
|
+ //System.out.println(funcid.getClassCode() + "\t" + funcid.getFirstTag() + "\t" + funcid.getSecondTag() + "\t" + funcid.getOrigCode() + "\t" + funcid.getName());
|
|
|
+ // update rwd_def_funcid set first_tag = '', second_tag = '' where class_code = '' and orig_code = '';
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.append("update rwd_def_funcid set first_tag = ")
|
|
|
+ .append(funcid.getFirstTag() == null ? null : "'" + funcid.getFirstTag().trim() + "'")
|
|
|
+ .append(", ")
|
|
|
+ .append("second_tag = ")
|
|
|
+ .append(funcid.getSecondTag() == null ? null : "'" + funcid.getSecondTag().trim() + "'")
|
|
|
+ .append(" where class_code = '").append(funcid.getClassCode()).append("'")
|
|
|
+ .append(" and orig_code = '").append(funcid.getOrigCode()).append("';")
|
|
|
+ ;
|
|
|
+
|
|
|
+ sqls.add(sql.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String sql : sqls) {
|
|
|
+ System.out.println(sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ workbook.close();
|
|
|
+ inputStream.close();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void importFuncidDef() throws IOException {
|
|
|
+ List<FuncidDefModel> funcids = new LinkedList<>();
|
|
|
+ importEquipment(funcids);
|
|
|
+
|
|
|
+ FileOutputStream fos = new FileOutputStream(outPath);
|
|
|
+ PrintWriter writer = new PrintWriter(new BufferedOutputStream(fos));
|
|
|
+ writer.println("commit;");
|
|
|
+ funcids.forEach(item -> {
|
|
|
// System.out.println(JacksonMapper.toSimpleJson(item));
|
|
|
- writer.println(toSql(item));
|
|
|
- });
|
|
|
- writer.println("commit;");
|
|
|
- writer.flush();
|
|
|
- writer.close();
|
|
|
- }
|
|
|
-
|
|
|
- private String toSql(FuncidDefModel model) {
|
|
|
- StringBuilder buff = new StringBuilder("");
|
|
|
- buff.append("insert into rwd_def_funcid ");
|
|
|
- buff.append("(id,code,orig_code,name,alias_code,alias_name,class_code,type,group_code,project_id,category,");
|
|
|
- buff.append("first_tag,second_tag,priority,input_mode,unit,data_type,orig_data_type,is_multiple,is_region,formater,data_source,orig_data_source,note,sub_flag,weak_point) ");
|
|
|
- buff.append("values (");
|
|
|
- buff.append("'").append(UUID.randomUUID().toString().replace("-", "")).append("',"); // id
|
|
|
- buff.append("'").append(model.getCode()).append("',"); // code
|
|
|
- buff.append("'").append(model.getOrigCode()).append("',"); // orig_code
|
|
|
- buff.append("'").append(model.getName()).append("',"); // name
|
|
|
- buff.append("'").append(model.getAliasCode()).append("',"); // alias_code
|
|
|
- buff.append("'").append(model.getAliasName()).append("',"); // alias_name
|
|
|
- buff.append("'").append(model.getClassCode()).append("',"); // class_code
|
|
|
- buff.append("'").append(model.getType()).append("',"); // type
|
|
|
- buff.append("'").append(model.getGroupCode()).append("',"); // group_code
|
|
|
- buff.append("'").append(model.getProjectId()).append("',"); // project_id
|
|
|
- buff.append("'").append(model.getCategory().name()).append("',"); // category
|
|
|
- if (model.getFirstTag() != null) {
|
|
|
- buff.append("'").append(model.getFirstTag()).append("',"); // first_tag
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getSecondTag() != null) {
|
|
|
- buff.append("'").append(model.getSecondTag()).append("',"); // second_tag
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getPriority() != null) {
|
|
|
- buff.append("'").append(model.getPriority()).append("',"); // priority
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getInputMode() != null) {
|
|
|
- buff.append("'").append(model.getInputMode()).append("',"); // input_mode
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getUnit() != null) {
|
|
|
- buff.append("'").append(model.getUnit()).append("',"); // unit
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
-
|
|
|
- buff.append("'").append(model.getDataType().name()).append("',"); // data_type
|
|
|
- buff.append("'").append(model.getOrigDataType()).append("',"); // orig_data_type
|
|
|
- buff.append(model.getIsMultiple() ? 1 : 0).append(","); // is_multiple
|
|
|
- buff.append(model.getIsRegion() ? 1 : 0).append(","); // is_region
|
|
|
- if (model.getFormater() != null) {
|
|
|
- buff.append("'").append(model.getFormater()).append("',"); // formater
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getDataSource() != null) {
|
|
|
- buff.append("'").append(model.getDataSource().toString()).append("',"); // data_source
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getOrigDataSource() != null) { // orig_data_source
|
|
|
- buff.append("'").append(model.getOrigDataSource()).append("',"); // data_source
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- if (model.getNote() != null) {
|
|
|
- buff.append("'").append(model.getNote()).append("',"); // note}
|
|
|
- } else {
|
|
|
- buff.append("null,");
|
|
|
- }
|
|
|
- buff.append(model.getSubFlag() ? 1 : 0).append(","); // sub_flag
|
|
|
- buff.append(model.getWeakPoint() ? 1 : 0).append(","); // weak_point
|
|
|
- buff.deleteCharAt(buff.length() - 1);
|
|
|
- buff.append(");");
|
|
|
- return buff.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private FuncidDefModel toFuncidDefModel(CacheModel model) {
|
|
|
- FuncidDefModel funcid = new FuncidDefModel();
|
|
|
- funcid.setGroupCode("0");
|
|
|
- funcid.setProjectId("0");
|
|
|
- funcid.setType("common");
|
|
|
- funcid.setClassCode(model.classCode);
|
|
|
- funcid.setFirstTag(model.firstTag != null ? model.firstTag.replace("\n", "") : null);
|
|
|
- funcid.setSecondTag(model.secondTag != null ? model.secondTag.replace("\n", "") : null);
|
|
|
- funcid.setCode(model.origCode.substring(0, 1).toLowerCase() + model.origCode.substring(1));
|
|
|
- funcid.setOrigCode(model.origCode);
|
|
|
- funcid.setAliasCode(model.origCode);
|
|
|
- if (model.name != null) {
|
|
|
- funcid.setName(model.name.replace("\n", ""));
|
|
|
- funcid.setAliasName(model.name.replace("\n", ""));
|
|
|
- } else {
|
|
|
- log.error("funcid name is null : {}", JacksonMapper.toSimpleJson(funcid));
|
|
|
- }
|
|
|
- funcid.setUnit(model.unit);
|
|
|
- funcid.setPriority(model.priority);
|
|
|
- funcid.setInputMode(model.inputMode);
|
|
|
- funcid.setOrigDataType(model.origDataType);
|
|
|
- funcid.setSubFlag(false);
|
|
|
- funcid.setWeakPoint(false);
|
|
|
- FuncidDefModel dataType = DataTypeMapping.getDataType(model.origDataType);
|
|
|
- if (dataType != null) {
|
|
|
- funcid.setCategory(dataType.getCategory());
|
|
|
- funcid.setDataType(dataType.getDataType());
|
|
|
- funcid.setIsMultiple(dataType.getIsMultiple());
|
|
|
- funcid.setIsRegion(dataType.getIsRegion());
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
- funcid.setSubFlag(false);
|
|
|
- if (model.remark != null) {
|
|
|
- funcid.setNote(model.remark.replace("\n", ""));
|
|
|
- }
|
|
|
-
|
|
|
- if (model.origDataSource != null) {
|
|
|
- funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
|
|
|
- }
|
|
|
- if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
|
|
|
- funcid.setDataSource(FuncidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
|
|
|
- }
|
|
|
- return funcid;
|
|
|
- }
|
|
|
-
|
|
|
- private void importEquipment(List<FuncidDefModel> funcids) throws IOException {
|
|
|
-
|
|
|
- funcids.addAll(readSheet("SELTLT", "/85-传感器.xlsx", "LTLT照明灯具"));
|
|
|
-
|
|
|
- funcids.addAll(readSheet("SELTCC", "/17-照明系统设备.xlsx", "LTCC照明回路"));
|
|
|
- funcids.addAll(readSheet("SELTLG", "/17-照明系统设备.xlsx", "LTLG照明灯组"));
|
|
|
-
|
|
|
- funcids.addAll(readSheet("SELTCU", "/17-照明系统设备.xlsx", "LTCU照明控制箱"));
|
|
|
- funcids.addAll(readSheet("SELTCP", "/17-照明系统设备.xlsx", "LTCP照明控制面板"));
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Data
|
|
|
- private static class CacheModel {
|
|
|
- private String classCode;
|
|
|
- private String firstTag;
|
|
|
- private String secondTag;
|
|
|
- private String origCode;
|
|
|
- private String name;
|
|
|
- private String unit;
|
|
|
- private String origDataType;
|
|
|
- private String priority; // 优先级
|
|
|
- private String inputMode;
|
|
|
- private String origDataSource; // 字典选择
|
|
|
- private String remark; // 备注
|
|
|
- }
|
|
|
-
|
|
|
- private List<FuncidDefModel> readSheet(String classCode, String fileName, String sheetName) throws IOException {
|
|
|
- List<FuncidDefModel> data = new LinkedList<>();
|
|
|
- String classFile = basepath + fileName;
|
|
|
- FileInputStream inputStream = new FileInputStream(classFile);
|
|
|
- Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
- Sheet sheet = workbook.getSheet(sheetName);
|
|
|
- if (sheet == null) {
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
- // 行号从0开始, 从第2行开始读数据
|
|
|
- int startRowNum = 2;
|
|
|
- int lastRowNum = sheet.getLastRowNum();
|
|
|
- CacheModel cache = new CacheModel();
|
|
|
- for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
|
|
|
- Row row = sheet.getRow(rowIndex);
|
|
|
- if (row == null) {
|
|
|
- log.info("file: {}, sheet: {}, row[{}] is null", fileName, sheetName, rowIndex);
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
|
|
|
- CacheModel target = new CacheModel();
|
|
|
- target.classCode = classCode;
|
|
|
- target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
|
|
|
- target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
|
|
|
- target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
|
|
|
- target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
|
|
|
- target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
|
|
|
- target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
|
|
|
- target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
|
|
|
- target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
|
|
|
- target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
|
|
|
- target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
|
|
|
-
|
|
|
- if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (FuncidUtils.isBase(target.origCode)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // firstTag不为空
|
|
|
- if (target.firstTag != null) {
|
|
|
- cache.firstTag = target.firstTag;
|
|
|
- cache.secondTag = null;
|
|
|
- } else {
|
|
|
- target.firstTag = cache.firstTag;
|
|
|
- }
|
|
|
-
|
|
|
- // secondTag
|
|
|
- if (target.secondTag != null) {
|
|
|
- cache.secondTag = target.secondTag;
|
|
|
- } else {
|
|
|
- target.secondTag = cache.secondTag;
|
|
|
- }
|
|
|
- FuncidDefModel funcidDefModel = toFuncidDefModel(target);
|
|
|
- if (funcidDefModel == null) {
|
|
|
- log.info("file: {}, sheet: {}, row: {} data type [{}] error", fileName, sheetName, rowIndex, target.origDataType);
|
|
|
- } else {
|
|
|
- data.add(funcidDefModel);
|
|
|
- }
|
|
|
- }
|
|
|
- return data;
|
|
|
- }
|
|
|
+ writer.println(toSql(item));
|
|
|
+ });
|
|
|
+ writer.println("commit;");
|
|
|
+ writer.flush();
|
|
|
+ writer.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String toSql(FuncidDefModel model) {
|
|
|
+ StringBuilder buff = new StringBuilder("");
|
|
|
+ buff.append("insert into rwd_def_funcid ");
|
|
|
+ buff.append("(id,code,orig_code,name,alias_code,alias_name,class_code,type,group_code,project_id,category,");
|
|
|
+ buff.append("first_tag,second_tag,priority,input_mode,unit,data_type,orig_data_type,is_multiple,is_region,formater,data_source,orig_data_source,note,sub_flag,weak_point) ");
|
|
|
+ buff.append("values (");
|
|
|
+ buff.append("'").append(UUID.randomUUID().toString().replace("-", "")).append("',"); // id
|
|
|
+ buff.append("'").append(model.getCode()).append("',"); // code
|
|
|
+ buff.append("'").append(model.getOrigCode()).append("',"); // orig_code
|
|
|
+ buff.append("'").append(model.getName()).append("',"); // name
|
|
|
+ buff.append("'").append(model.getAliasCode()).append("',"); // alias_code
|
|
|
+ buff.append("'").append(model.getAliasName()).append("',"); // alias_name
|
|
|
+ buff.append("'").append(model.getClassCode()).append("',"); // class_code
|
|
|
+ buff.append("'").append(model.getType()).append("',"); // type
|
|
|
+ buff.append("'").append(model.getGroupCode()).append("',"); // group_code
|
|
|
+ buff.append("'").append(model.getProjectId()).append("',"); // project_id
|
|
|
+ buff.append("'").append(model.getCategory().name()).append("',"); // category
|
|
|
+ if (model.getFirstTag() != null) {
|
|
|
+ buff.append("'").append(model.getFirstTag()).append("',"); // first_tag
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getSecondTag() != null) {
|
|
|
+ buff.append("'").append(model.getSecondTag()).append("',"); // second_tag
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getPriority() != null) {
|
|
|
+ buff.append("'").append(model.getPriority()).append("',"); // priority
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getInputMode() != null) {
|
|
|
+ buff.append("'").append(model.getInputMode()).append("',"); // input_mode
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getUnit() != null) {
|
|
|
+ buff.append("'").append(model.getUnit()).append("',"); // unit
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+
|
|
|
+ buff.append("'").append(model.getDataType().name()).append("',"); // data_type
|
|
|
+ buff.append("'").append(model.getOrigDataType()).append("',"); // orig_data_type
|
|
|
+ buff.append(model.getIsMultiple() ? 1 : 0).append(","); // is_multiple
|
|
|
+ buff.append(model.getIsRegion() ? 1 : 0).append(","); // is_region
|
|
|
+ if (model.getFormater() != null) {
|
|
|
+ buff.append("'").append(model.getFormater()).append("',"); // formater
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getDataSource() != null) {
|
|
|
+ buff.append("'").append(model.getDataSource().toString()).append("',"); // data_source
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getOrigDataSource() != null) { // orig_data_source
|
|
|
+ buff.append("'").append(model.getOrigDataSource()).append("',"); // data_source
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ if (model.getNote() != null) {
|
|
|
+ buff.append("'").append(model.getNote()).append("',"); // note}
|
|
|
+ } else {
|
|
|
+ buff.append("null,");
|
|
|
+ }
|
|
|
+ buff.append(model.getSubFlag() ? 1 : 0).append(","); // sub_flag
|
|
|
+ buff.append(model.getWeakPoint() ? 1 : 0).append(","); // weak_point
|
|
|
+ buff.deleteCharAt(buff.length() - 1);
|
|
|
+ buff.append(");");
|
|
|
+ return buff.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private FuncidDefModel toFuncidDefModel(CacheModel model) {
|
|
|
+ FuncidDefModel funcid = new FuncidDefModel();
|
|
|
+ funcid.setGroupCode("0");
|
|
|
+ funcid.setProjectId("0");
|
|
|
+ funcid.setType("common");
|
|
|
+ funcid.setClassCode(model.classCode);
|
|
|
+ funcid.setFirstTag(model.firstTag != null ? model.firstTag.replace("\n", "") : null);
|
|
|
+ funcid.setSecondTag(model.secondTag != null ? model.secondTag.replace("\n", "") : null);
|
|
|
+ funcid.setCode(model.origCode.substring(0, 1).toLowerCase() + model.origCode.substring(1));
|
|
|
+ funcid.setOrigCode(model.origCode);
|
|
|
+ funcid.setAliasCode(model.origCode);
|
|
|
+ if (model.name != null) {
|
|
|
+ funcid.setName(model.name.replace("\n", ""));
|
|
|
+ funcid.setAliasName(model.name.replace("\n", ""));
|
|
|
+ } else {
|
|
|
+ log.error("funcid name is null : {}", JacksonMapper.toSimpleJson(funcid));
|
|
|
+ }
|
|
|
+ funcid.setUnit(model.unit);
|
|
|
+ funcid.setPriority(model.priority);
|
|
|
+ funcid.setInputMode(model.inputMode);
|
|
|
+ funcid.setOrigDataType(model.origDataType);
|
|
|
+ funcid.setSubFlag(false);
|
|
|
+ funcid.setWeakPoint(false);
|
|
|
+ FuncidDefModel dataType = DataTypeMapping.getDataType(model.origDataType);
|
|
|
+ if (dataType != null) {
|
|
|
+ funcid.setCategory(dataType.getCategory());
|
|
|
+ funcid.setDataType(dataType.getDataType());
|
|
|
+ funcid.setIsMultiple(dataType.getIsMultiple());
|
|
|
+ funcid.setIsRegion(dataType.getIsRegion());
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ funcid.setSubFlag(false);
|
|
|
+ if (model.remark != null) {
|
|
|
+ funcid.setNote(model.remark.replace("\n", ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (model.origDataSource != null) {
|
|
|
+ funcid.setOrigDataSource(model.origDataSource.replace("\n", "nn")); // 去掉换行符
|
|
|
+ }
|
|
|
+ if (funcid.getDataType() == FuncidDataType.ENUM || funcid.getDataType() == FuncidDataType.MENUM || funcid.getDataType() == FuncidDataType.BOOLEAN) {
|
|
|
+ FuncidUtils funcidUtils = new FuncidUtils();
|
|
|
+ funcid.setDataSource(funcidUtils.transEnumDataSource(model.origDataSource)); // 解析datasource
|
|
|
+ }
|
|
|
+ return funcid;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void importEquipment(List<FuncidDefModel> funcids) throws IOException {
|
|
|
+
|
|
|
+ funcids.addAll(readSheet("SELTLT", "/85-传感器.xlsx", "LTLT照明灯具"));
|
|
|
+
|
|
|
+ funcids.addAll(readSheet("SELTCC", "/17-照明系统设备.xlsx", "LTCC照明回路"));
|
|
|
+ funcids.addAll(readSheet("SELTLG", "/17-照明系统设备.xlsx", "LTLG照明灯组"));
|
|
|
+
|
|
|
+ funcids.addAll(readSheet("SELTCU", "/17-照明系统设备.xlsx", "LTCU照明控制箱"));
|
|
|
+ funcids.addAll(readSheet("SELTCP", "/17-照明系统设备.xlsx", "LTCP照明控制面板"));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ private static class CacheModel {
|
|
|
+ private String classCode;
|
|
|
+ private String firstTag;
|
|
|
+ private String secondTag;
|
|
|
+ private String origCode;
|
|
|
+ private String name;
|
|
|
+ private String unit;
|
|
|
+ private String origDataType;
|
|
|
+ private String priority; // 优先级
|
|
|
+ private String inputMode;
|
|
|
+ private String origDataSource; // 字典选择
|
|
|
+ private String remark; // 备注
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<FuncidDefModel> readSheet(String classCode, String fileName, String sheetName) throws IOException {
|
|
|
+ List<FuncidDefModel> data = new LinkedList<>();
|
|
|
+ String classFile = basepath + fileName;
|
|
|
+ FileInputStream inputStream = new FileInputStream(classFile);
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+ Sheet sheet = workbook.getSheet(sheetName);
|
|
|
+ if (sheet == null) {
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 行号从0开始, 从第2行开始读数据
|
|
|
+ int startRowNum = 2;
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ CacheModel cache = new CacheModel();
|
|
|
+ for (int rowIndex = startRowNum; rowIndex <= lastRowNum; rowIndex++) {
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ log.info("file: {}, sheet: {}, row[{}] is null", fileName, sheetName, rowIndex);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 0:firstTag, 1:secondTag, 2:name, 3:origCode, 4:unit, 5:origDataType, 6:priorite, 7:imputMode, 8:origDataSource, 9:remark
|
|
|
+ CacheModel target = new CacheModel();
|
|
|
+ target.classCode = classCode;
|
|
|
+ target.firstTag = (String) ExcelUtils.parseCell(row.getCell(0), "string");
|
|
|
+ target.secondTag = (String) ExcelUtils.parseCell(row.getCell(1), "string");
|
|
|
+ target.name = (String) ExcelUtils.parseCell(row.getCell(2), "string");
|
|
|
+ target.origCode = (String) ExcelUtils.parseCell(row.getCell(3), "string");
|
|
|
+ target.unit = (String) ExcelUtils.parseCell(row.getCell(4), "string");
|
|
|
+ target.origDataType = (String) ExcelUtils.parseCell(row.getCell(5), "string");
|
|
|
+ target.priority = (String) ExcelUtils.parseCell(row.getCell(6), "string");
|
|
|
+ target.inputMode = (String) ExcelUtils.parseCell(row.getCell(7), "string");
|
|
|
+ target.origDataSource = (String) ExcelUtils.parseCell(row.getCell(8), "string");
|
|
|
+ target.remark = (String) ExcelUtils.parseCell(row.getCell(9), "string");
|
|
|
+
|
|
|
+ if (target.origCode == null || "".equals(target.origCode) || "`".equals(target.origCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (FuncidUtils.isBase(target.origCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // firstTag不为空
|
|
|
+ if (target.firstTag != null) {
|
|
|
+ cache.firstTag = target.firstTag;
|
|
|
+ cache.secondTag = null;
|
|
|
+ } else {
|
|
|
+ target.firstTag = cache.firstTag;
|
|
|
+ }
|
|
|
+
|
|
|
+ // secondTag
|
|
|
+ if (target.secondTag != null) {
|
|
|
+ cache.secondTag = target.secondTag;
|
|
|
+ } else {
|
|
|
+ target.secondTag = cache.secondTag;
|
|
|
+ }
|
|
|
+ FuncidDefModel funcidDefModel = toFuncidDefModel(target);
|
|
|
+ if (funcidDefModel == null) {
|
|
|
+ log.info("file: {}, sheet: {}, row: {} data type [{}] error", fileName, sheetName, rowIndex, target.origDataType);
|
|
|
+ } else {
|
|
|
+ data.add(funcidDefModel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|