|
@@ -0,0 +1,521 @@
|
|
|
|
+package com.ventanaly;//import com.ventanaly.device.facility.fanMain.FanMainSXFacility;
|
|
|
|
+//import com.ventanaly.device.facility.fanMain.FanMainSgtFacility;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+public class FastPlcGenerate {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 风机类型 主扇:Main 局扇:System
|
|
|
|
+ public static String FAN_TYPE="Main";
|
|
|
|
+
|
|
|
|
+ //矿井唯一表示,万里一矿--->Wl1k
|
|
|
|
+ public static String MINE_NAME="Wl1k";
|
|
|
|
+
|
|
|
|
+ //设备名称
|
|
|
|
+ public static String DEVICE_NAME="万里一矿主扇";
|
|
|
|
+
|
|
|
|
+ // Excel文件路径
|
|
|
|
+ public static String EXCEL_FILE_PATH = "template/wl1k.xlsx";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static String ENUM_NAME = "Fan"+FAN_TYPE+MINE_NAME+"Enum";
|
|
|
|
+
|
|
|
|
+ public static String ENUM_PREFIX = "FAN_"+FAN_TYPE.toUpperCase()+"_"+MINE_NAME.toUpperCase()+"_ENUM_";
|
|
|
|
+
|
|
|
|
+ public static String FROM_NAME = "Fan"+FAN_TYPE+MINE_NAME+"From";
|
|
|
|
+
|
|
|
|
+ public static String VO_NAME = "Fan"+FAN_TYPE+MINE_NAME+"Vo";
|
|
|
|
+
|
|
|
|
+ public static String FACILITY_NAME = "Fan"+FAN_TYPE+MINE_NAME+"Facility";
|
|
|
|
+
|
|
|
|
+ public static String FACILITY_REF_NAME = "fan"+FAN_TYPE+MINE_NAME+"Facility";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+
|
|
|
|
+ // 指定输出文件的路径
|
|
|
|
+ String filePath = "generate/"+MINE_NAME+".txt";
|
|
|
|
+
|
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
|
+
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+
|
|
|
|
+ String nowDate = currentDate.format(formatter);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ PrintStream out = new PrintStream(Files.newOutputStream(Paths.get(filePath)));
|
|
|
|
+
|
|
|
|
+ // 将System.out设置为新的PrintStream实例
|
|
|
|
+ System.setOut(out);
|
|
|
|
+
|
|
|
|
+ FileInputStream fis = new FileInputStream(EXCEL_FILE_PATH);
|
|
|
|
+ Workbook workbook = new XSSFWorkbook(fis);
|
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
+
|
|
|
|
+ List<String> columnNameList = new ArrayList<>();
|
|
|
|
+ List<String> typeList = new ArrayList<>();
|
|
|
|
+ List<String> chineseExplanationList = new ArrayList<>();
|
|
|
|
+ List<String> accessModeList = new ArrayList<>();
|
|
|
|
+ List<String> pointsList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (Row row : sheet) {
|
|
|
|
+ if (row.getRowNum() == 0) continue; // 跳过标题行
|
|
|
|
+
|
|
|
|
+ Cell columnNameCell = row.getCell(0);
|
|
|
|
+ Cell typeCell = row.getCell(1);
|
|
|
|
+ Cell chineseExplanationCell = row.getCell(2);
|
|
|
|
+ Cell accessModeCell = row.getCell(3);
|
|
|
|
+ Cell pointsCell = row.getCell(4);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ columnNameList.add(getCellValueAsString(columnNameCell));
|
|
|
|
+ typeList.add(getCellValueAsString(typeCell));
|
|
|
|
+ chineseExplanationList.add(getCellValueAsString(chineseExplanationCell));
|
|
|
|
+ accessModeList.add(getCellValueAsString(accessModeCell));
|
|
|
|
+ pointsList.add(getCellValueAsString(pointsCell));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String[] colArray = columnNameList.toArray(new String[0]);
|
|
|
|
+ String[] typeArray = typeList.toArray(new String[0]);
|
|
|
|
+ String[] notesArray = chineseExplanationList.toArray(new String[0]);
|
|
|
|
+ String[] accessModes = accessModeList.toArray(new String[0]);
|
|
|
|
+ String[] pointsArray = pointsList.toArray(new String[0]);
|
|
|
|
+ System.out.println("监测实体类====================================================================");
|
|
|
|
+ creatVoEntity(colArray,typeArray,notesArray,accessModes,nowDate);
|
|
|
|
+ System.out.println("控制实体类====================================================================");
|
|
|
|
+ creatFromEntity(colArray,typeArray,notesArray,accessModes,nowDate);
|
|
|
|
+ System.out.println("枚举=========================================================================");
|
|
|
|
+ creatEnum(colArray,notesArray,pointsArray,accessModes,nowDate);
|
|
|
|
+ System.out.println("业务实现类=====================================================================");
|
|
|
|
+ creatFacility(colArray,typeArray,notesArray,accessModes,false,"1","1",nowDate);
|
|
|
|
+ System.out.println("控制方法实现====================================================================");
|
|
|
|
+ createServiceControl(colArray,notesArray,accessModes,nowDate);
|
|
|
|
+ System.out.println();
|
|
|
|
+ System.out.println("监测方法片段====================================================================");
|
|
|
|
+ createServiceMonitor(nowDate);
|
|
|
|
+ System.out.println("点表配置json====================================================================");
|
|
|
|
+ creatDBJSON(colArray,pointsArray);
|
|
|
|
+ System.out.println("点位解释json====================================================================");
|
|
|
|
+ createInterpret(colArray,notesArray,accessModes);
|
|
|
|
+ System.out.println("控制请求表格====================================================================");
|
|
|
|
+ createReqFormDoc(colArray,notesArray,typeArray,accessModes);
|
|
|
|
+
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static String getCellValueAsString(Cell cell) {
|
|
|
|
+ if (cell == null) return "";
|
|
|
|
+
|
|
|
|
+ switch (cell.getCellType()) {
|
|
|
|
+ case STRING:
|
|
|
|
+ return cell.getStringCellValue().trim();
|
|
|
|
+ case NUMERIC:
|
|
|
|
+ return String.valueOf(cell.getNumericCellValue());
|
|
|
|
+ case BOOLEAN:
|
|
|
|
+ return String.valueOf(cell.getBooleanCellValue());
|
|
|
|
+ case FORMULA:
|
|
|
|
+ return cell.getCellFormula();
|
|
|
|
+ case BLANK:
|
|
|
|
+ return "";
|
|
|
|
+ default:
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void createServiceControl(String[] colArray,String[] notesArray,String[] accessModes,String nowDate){
|
|
|
|
+ System.out.println(" //"+DEVICE_NAME+" "+nowDate);
|
|
|
|
+ System.out.println(" public boolean controlFan"+FAN_TYPE+MINE_NAME+"(Fan"+FAN_TYPE+"From from, Json json, FanMainPage fm, UserLogPage ulPage) {\n");
|
|
|
|
+ System.out.println(" boolean r = false;\n" +
|
|
|
|
+ " ulPage.setDeviceType(4);\n" +
|
|
|
|
+ " DeviceRelationPage dr = SubStationStatic.DRMap.get(from.getId());\n" +
|
|
|
|
+ " if (null == dr) {\n" +
|
|
|
|
+ " throw new ServiceException(\"不存在的分站\");\n" +
|
|
|
|
+ " }\n" +
|
|
|
|
+ " SubStationPage page = dr.getSubStationPage();\n" +
|
|
|
|
+ " try {\n" +
|
|
|
|
+ " RelationVo g = (RelationVo) dr.getObjVo();\n" +
|
|
|
|
+ " from.setStrInstallPos(g.getStrInstallPos());\n" +
|
|
|
|
+ " } catch (Exception e) {\n" +
|
|
|
|
+ " e.printStackTrace();\n" +
|
|
|
|
+ " }\n" +
|
|
|
|
+ " Map<String, String> tableMeta = SubStationStatic.tableMetas.get(dr.getPLC_table());\n" +
|
|
|
|
+ " json.setMsg(\"无任何操作\");\n" +
|
|
|
|
+ " if (dr.getDevice_id() != fm.getNFanID()) {\n" +
|
|
|
|
+ " throw new ServiceException(\"输入密码不正确\");\n" +
|
|
|
|
+ " }\n" +
|
|
|
|
+ " SensorNet net = page.getSensorNet();");
|
|
|
|
+ System.out.println(" if (!dr.getIsFake()) {\n" +
|
|
|
|
+ " if (!net.getState()) {\n" +
|
|
|
|
+ " json.setMsg(\"无任何操作\");\n" +
|
|
|
|
+ " throw new ServiceException(\"无法与设备建立链接\");\n" +
|
|
|
|
+ " }\n");
|
|
|
|
+
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if ("只读".equals(accessModes[i])){continue;}
|
|
|
|
+ Character c = colArray[i].charAt(0);
|
|
|
|
+ String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
|
|
|
|
+ System.out.println(" if (null != from.get"+FROM_NAME+"().get"+newCol+"()) {");
|
|
|
|
+ System.out.println(" logger.info(\""+notesArray[i]+"--->\" + from.get"+FROM_NAME+"().get"+newCol+"());");
|
|
|
|
+ System.out.println(" json.setMsg(\""+notesArray[i]+"\");");
|
|
|
|
+ System.out.println(" ulPage.setRecord(\""+notesArray[i]+":\" + from.get"+FROM_NAME+"().get"+newCol+"());");
|
|
|
|
+ System.out.println(" r = "+FACILITY_REF_NAME+"."+colArray[i]+"(from, net, tableMeta, null);");
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ System.out.println();
|
|
|
|
+ }
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ System.out.println(" return r;\n" +
|
|
|
|
+ " }");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void createServiceMonitor(String nowDate){
|
|
|
|
+ System.out.println(" //"+DEVICE_NAME+" "+nowDate);
|
|
|
|
+ System.out.println(" case Fan"+FAN_TYPE+MINE_NAME+"Facility.TYPE:\n" +
|
|
|
|
+ " vo = fan"+FAN_TYPE+MINE_NAME+"Facility.status(dr,tableMeta,page);\n" +
|
|
|
|
+ " break;");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void creatFacility(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes,boolean flag,String cy,String num,String nowDate){
|
|
|
|
+ System.out.println("import com.ventanaly.tool.enums.PLCDevice2Enum;\n" +
|
|
|
|
+ "import com.ventanaly.tool.froms.FanMainFrom;\n" +
|
|
|
|
+ "import com.ventanaly.tool.page.FanMainPage;\n" +
|
|
|
|
+ "import com.ventanaly.tool.utils.Constants;\n" +
|
|
|
|
+ "import com.ventanaly.tool.page.DeviceRelationPage;\n" +
|
|
|
|
+ "import com.ventanaly.tool.page.SubStationPage;\n" +
|
|
|
|
+ "import com.ventanaly.tool.utils.SensorNet;\n" +
|
|
|
|
+ "import org.slf4j.Logger;\n" +
|
|
|
|
+ "import org.slf4j.LoggerFactory;\n" +
|
|
|
|
+ "import org.springframework.stereotype.Component;\n" +
|
|
|
|
+ "import java.util.Map;");
|
|
|
|
+
|
|
|
|
+ System.out.println(" //"+DEVICE_NAME+" "+nowDate);
|
|
|
|
+ System.out.println("@Component");
|
|
|
|
+ System.out.println("public class "+FACILITY_NAME+" {");
|
|
|
|
+ System.out.println("\n" +
|
|
|
|
+ " private final Logger logger = LoggerFactory.getLogger(getClass());");
|
|
|
|
+ System.out.println(" public static final String TYPE = \"fan_"+FAN_TYPE.toLowerCase()+"_"+MINE_NAME.toLowerCase()+"\";");
|
|
|
|
+ System.out.println(" public static final String TYPE_NAME = "+"\""+DEVICE_NAME+"\""+";\n" +
|
|
|
|
+ " private static boolean control = true;\n" +
|
|
|
|
+ "\n");
|
|
|
|
+ System.out.println(" public "+VO_NAME+" fan"+ FAN_TYPE +MINE_NAME+"Status(DeviceRelationPage dr, Map<String, String> tableMeta, FanMainPage page) {\n");
|
|
|
|
+ System.out.println(" "+VO_NAME+" vo = new "+ VO_NAME+"();");
|
|
|
|
+ System.out.println(" vo.setDeviceType(Constants.DEVICE_TYPE_FAN_"+FAN_TYPE.toUpperCase()+");");
|
|
|
|
+ System.out.println(" vo.setSmallType(TYPE);");
|
|
|
|
+ System.out.println(" vo.setDeviceId(dr.getDevice_id());");
|
|
|
|
+ System.out.println(" vo.setId(dr.getId());");
|
|
|
|
+ System.out.println(" SubStationPage sp = dr.getSubStationPage();");
|
|
|
|
+ System.out.println(" if (null == sp) {");
|
|
|
|
+ System.out.println(" return vo;");
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ System.out.println(" SensorNet net = sp.getSensorNet();");
|
|
|
|
+ System.out.println(" vo.setNetStatus(net.isLinkState() ? 1 : 0);");
|
|
|
|
+ System.out.println(" if (1 == vo.getNetStatus()) {");
|
|
|
|
+ System.out.println(" String address;");
|
|
|
|
+ System.out.println(" String tName;");
|
|
|
|
+ System.out.println(" vo.setUrl(net.getIp());");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if ("只写".equals(accessModes[i])){continue;}
|
|
|
|
+
|
|
|
|
+ System.out.println(" tName = PLCDevice2Enum."+ENUM_NAME+"."+ENUM_PREFIX + colArray[i].toUpperCase() + ".getName();");
|
|
|
|
+ System.out.println(" address = tableMeta.get(tName);");
|
|
|
|
+ if("Boolean".equals(typeArray[i])){
|
|
|
|
+ System.out.println(" "+typeArray[i] + " " + colArray[i] + " = net.getSensorBoolean(address);");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println(" "+typeArray[i] + " " + colArray[i] + " = net.getSensor" + typeArray[i] + "(address);");
|
|
|
|
+ }
|
|
|
|
+ if(flag && !"Boolean".equals(typeArray[i])){
|
|
|
|
+ System.out.println(" "+"BigDecimal"+" "+ colArray[i] + "Val = StringUtils.roundHalfUp("+colArray[i]+"*"+cy+","+num+");");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println(" "+"logger.debug(\"" + notesArray[i] + "-ID:{}-点位名称:{},address:{},Val:{}\", dr.getId(), tName, address, " + colArray[i] + ");");
|
|
|
|
+ Character c = colArray[i].charAt(0);
|
|
|
|
+ String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
|
|
|
|
+ if(flag && !"Boolean".equals(typeArray[i])){
|
|
|
|
+ System.out.println(" "+"vo.set" + newCol + "(" + colArray[i] + "Val.floatValue());");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println(" "+"vo.set" + newCol + "(" + colArray[i] + ");");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.out.println();
|
|
|
|
+ }
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ System.out.println(" dr.setObjVo(vo);\n" +
|
|
|
|
+ " return vo;");
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ creatControl(colArray,typeArray,notesArray,accessModes);
|
|
|
|
+ System.out.println("}");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *生成实体类
|
|
|
|
+ * @param colArray 字段
|
|
|
|
+ * @param typeArray 字段类型
|
|
|
|
+ * @param notesArray 字段解释
|
|
|
|
+ */
|
|
|
|
+ public static void creatEntity(String[] colArray,String[] typeArray,String[] notesArray){
|
|
|
|
+ //都用逗号隔开
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ System.out.println("@JsonProperty(value = " + "\"" + colArray[i] + "\"" + ")");
|
|
|
|
+ System.out.println("private " + typeArray[i] + " " + colArray[i] + "; //" + notesArray[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //生成监测实体类
|
|
|
|
+ public static void creatVoEntity(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes,String nowDate){
|
|
|
|
+ System.out.println(" //"+DEVICE_NAME+" "+nowDate);
|
|
|
|
+ System.out.println("@Data");
|
|
|
|
+ System.out.println("public class "+VO_NAME+" extends RelationVo {");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if ("只写".equals(accessModes[i])){continue;}
|
|
|
|
+ System.out.println(" @JsonProperty(value = " + "\"" + colArray[i] + "\"" + ")");
|
|
|
|
+ System.out.println(" private " + typeArray[i] + " " + colArray[i] + "; //" + notesArray[i]);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("}");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //生成控制请求类
|
|
|
|
+ public static void creatFromEntity(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes,String nowDate){
|
|
|
|
+ System.out.println(" //"+DEVICE_NAME+" "+nowDate);
|
|
|
|
+ System.out.println("@Data");
|
|
|
|
+ System.out.println("public class "+FROM_NAME+"{");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if ("只读".equals(accessModes[i])){continue;}
|
|
|
|
+ System.out.println(" @JsonProperty(value = " + "\"" + colArray[i] + "\"" + ")");
|
|
|
|
+ System.out.println(" private " + typeArray[i] + " " + colArray[i] + "; //" + notesArray[i]);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("}");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成Enum
|
|
|
|
+ * @param colArray 字段
|
|
|
|
+ * @param notesArray 字段解释
|
|
|
|
+ */
|
|
|
|
+ public static void creatEnum(String[] colArray,String[] notesArray,String[] pointsArray,String[] accessModes,String nowDate){
|
|
|
|
+ String befStr = ENUM_PREFIX;
|
|
|
|
+ System.out.println(" //"+DEVICE_NAME+" "+nowDate);
|
|
|
|
+ System.out.println(" public enum Fan"+FAN_TYPE+MINE_NAME+"Enum {");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if (i!=colArray.length-1){
|
|
|
|
+
|
|
|
|
+ System.out.println(" "+befStr + colArray[i].toUpperCase() + "(" + "\"" + colArray[i] + "\", \"" + notesArray[i] + "\", \"" +pointsArray[i]+ "\"" +"),");
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ System.out.println(" "+befStr + colArray[i].toUpperCase() + "(" + "\"" + colArray[i] + "\", \"" + notesArray[i] + "\", \"" +pointsArray[i]+ "\"" +");");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("\n" +
|
|
|
|
+ " private String name; //状态位/控制位\n" +
|
|
|
|
+ " private String message; //指令描述\n" +
|
|
|
|
+ " private String point;");
|
|
|
|
+ System.out.println(" Fan"+FAN_TYPE+MINE_NAME+"Enum(String name, String message,String point) {\n" +
|
|
|
|
+ " this.name = name;\n" +
|
|
|
|
+ " this.message = message;\n" +
|
|
|
|
+ " this.point = point;\n" +
|
|
|
|
+ " }\n");
|
|
|
|
+ System.out.println(" public String getName() {\n" +
|
|
|
|
+ " return name;\n" +
|
|
|
|
+ " }\n" +
|
|
|
|
+ "\n" +
|
|
|
|
+ " public String getMessage() {\n" +
|
|
|
|
+ " return message;\n" +
|
|
|
|
+ " }\n" +
|
|
|
|
+ "\n" +
|
|
|
|
+ " public String getPoint(){return point;}\n" +
|
|
|
|
+ " }");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成Enum
|
|
|
|
+ * @param colArray 字段
|
|
|
|
+ * @param lcsxArray 量程上限字段
|
|
|
|
+ * @param lcxxArray 量程下限字段
|
|
|
|
+ * @param bjsxArray 报警上限
|
|
|
|
+ * @param bjxxArray 报警下限
|
|
|
|
+ */
|
|
|
|
+ public static void creatFtpEnum(String[] colArray,String[] lcsxArray,String[] lcxxArray,String[] bjsxArray,String[] bjxxArray,String[] notesArray){
|
|
|
|
+ String befStr = "FAN_MAIN_TLH_ENUM_";
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ int id = i + 1;
|
|
|
|
+ String val ="" + id + "," + lcsxArray[i] + "," + lcxxArray[i] + "," + bjsxArray[i] + "," + bjxxArray[i];
|
|
|
|
+ System.out.print(befStr + colArray[i].toUpperCase() + "(" + "\"" + colArray[i] + "\", \"" + val + "\"" + "),");
|
|
|
|
+ System.out.println("//" + notesArray[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成点表json字符串
|
|
|
|
+ * @param colArray 字段
|
|
|
|
+ * @param dbArray 点位地址/id
|
|
|
|
+ */
|
|
|
|
+ public static void creatDBJSON(String[] colArray , String[] dbArray){
|
|
|
|
+ StringBuffer str = new StringBuffer();
|
|
|
|
+ str.append("{");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++)
|
|
|
|
+ {
|
|
|
|
+ str.append("\"");
|
|
|
|
+ //拼接请求json数据格式["",""]
|
|
|
|
+ str.append(colArray[i]);
|
|
|
|
+ str.append("\"");
|
|
|
|
+ str.append(":");
|
|
|
|
+ str.append("\"");
|
|
|
|
+ str.append(dbArray[i]);
|
|
|
|
+ str.append("\"");
|
|
|
|
+ if(i==colArray.length-1) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ str.append(",");
|
|
|
|
+ }
|
|
|
|
+ str.append("}");
|
|
|
|
+ System.out.println(str.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成测试模拟数据代码
|
|
|
|
+ * @param colArray 字段
|
|
|
|
+ * @param typeArray 字段类型
|
|
|
|
+ */
|
|
|
|
+ public static void creatTestData(String[] colArray , String[] typeArray){
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ Character c = colArray[i].charAt(0);
|
|
|
|
+ String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
|
|
|
|
+ String val = "";
|
|
|
|
+ if("boolean".equals(typeArray[i]) || "Boolean".equals(typeArray[i])){
|
|
|
|
+ val = "(true";
|
|
|
|
+ }else{
|
|
|
|
+ val = "(setVal(10f, 5f)";
|
|
|
|
+ }
|
|
|
|
+ System.out.println("vo.set" + newCol + val + ");");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *生成实体类
|
|
|
|
+ */
|
|
|
|
+ public static void creatEntity2(String col,String type,String note){
|
|
|
|
+ //都用逗号隔开
|
|
|
|
+ for(int i = 0;i<540;i++){
|
|
|
|
+ System.out.println("@JsonProperty(value = " + "\"" + col + i + "\"" + ")");
|
|
|
|
+ System.out.println("private " + type + " " + col + i + "; //" + note);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 生成控制代码
|
|
|
|
+ * @param colArray
|
|
|
|
+ * @param typeArray
|
|
|
|
+ * @param notesArray
|
|
|
|
+ */
|
|
|
|
+ public static void creatControl(String[] colArray,String[] typeArray,String[] notesArray,String[] accessModes){
|
|
|
|
+
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+
|
|
|
|
+ if ("只读".equals(accessModes[i])){continue;}
|
|
|
|
+ System.out.println(" //"+notesArray[i]);
|
|
|
|
+ System.out.println(" public boolean " + colArray[i] + "(Fan"+FAN_TYPE+"From from, SensorNet net, Map<String, String> tableMeta, Long timeout) {");
|
|
|
|
+ System.out.println(" boolean result = false;");
|
|
|
|
+ System.out.println(" if (control) {");
|
|
|
|
+ System.out.println(" control = false;");
|
|
|
|
+ Character c = colArray[i].charAt(0);
|
|
|
|
+ String newCol = c.toUpperCase(c) + colArray[i].substring(1,colArray[i].length());
|
|
|
|
+ System.out.println(" String tName = PLCDevice2Enum."+ENUM_NAME+"."+ENUM_PREFIX + colArray[i].toUpperCase() + ".getName();");
|
|
|
|
+ System.out.println(" String address = tableMeta.get(tName);");
|
|
|
|
+ System.out.println(" try {");
|
|
|
|
+ if("Boolean".equals(typeArray[i]) || "boolean".equals(typeArray[i])){
|
|
|
|
+ System.out.println(" result = net.setSensor(address,Constants.PLC_BOOLEAN_TRUE);");
|
|
|
|
+ System.out.println(" logger.debug(\"设置-" + notesArray[i] + "-点位名称:{},address:{},Val:{}\"" + ", tName, address, Constants.PLC_BOOLEAN_TRUE);");
|
|
|
|
+ System.out.println(" Thread.sleep(1000);");
|
|
|
|
+ }else{
|
|
|
|
+ System.out.println(" result = net.setSensor(address,from.get"+FROM_NAME+"().get" + newCol + "());");
|
|
|
|
+ System.out.println(" logger.debug(\"设置-" + notesArray[i] + "-点位名称:{},address:{},Val:{}\"" + ", tName, address, from.get"+FROM_NAME+"().get" + newCol + "());");
|
|
|
|
+ }
|
|
|
|
+ System.out.println(" } catch (Throwable e) {");
|
|
|
|
+ System.out.println(" e.printStackTrace();");
|
|
|
|
+ System.out.println(" } finally {");
|
|
|
|
+ System.out.println(" control = true;");
|
|
|
|
+// if("Boolean".equals(typeArray[i]) || "boolean".equals(typeArray[i])){
|
|
|
|
+// System.out.println(" result = net.setSensor(address,Constants.PLC_BOOLEAN_FALSE);");
|
|
|
|
+// System.out.println(" logger.debug(\"回位-" + notesArray[i] + "-点位名称:{},address:{},Val:{}\"" + ", tName, address, Constants.PLC_BOOLEAN_FALSE);");
|
|
|
|
+// }
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ System.out.println(" return result;");
|
|
|
|
+ System.out.println(" }");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //生成文档中点位表解释
|
|
|
|
+ public static void createInterpret(String[] colArray,String[] notesArray,String[] accessModes){
|
|
|
|
+ System.out.println("{");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if ("只写".equals(accessModes[i])){continue;}
|
|
|
|
+ if (i!=colArray.length-1){
|
|
|
|
+ System.out.println("\"" + colArray[i] + "\""+":"+"\""+notesArray[i]+"\""+",");
|
|
|
|
+ }else {
|
|
|
|
+ System.out.println("\"" + colArray[i] + "\""+":"+"\""+notesArray[i]+"\"");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("}");
|
|
|
|
+ }
|
|
|
|
+ //生成 文档中控制命令的请求参数表单
|
|
|
|
+ public static void createReqFormDoc(String[] colArray,String[] notesArray,String[] typeArray,String[] accessModes){
|
|
|
|
+ System.out.println("|参数名|必选|类型|说明|");
|
|
|
|
+ System.out.println("|:---- |:---|:----- |----- |");
|
|
|
|
+ for(int i = 0;i<colArray.length;i++){
|
|
|
|
+ if ("只读".equals(accessModes[i])){continue;}
|
|
|
|
+ System.out.println("|"+colArray[i]+"|否|"+typeArray[i]+"|"+notesArray[i]+"|");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //生成设备接入时控制文档
|
|
|
|
+// public static void createControlDoc(){
|
|
|
|
+// PLCDevice2Enum.FanMainSgtEnum[] values = PLCDevice2Enum.FanMainSgtEnum.values();
|
|
|
|
+// FanMainSgtFacility fanMainSgtFacility = new FanMainSgtFacility();
|
|
|
|
+// Class<? extends FanMainSgtFacility> aClass = fanMainSgtFacility.getClass();
|
|
|
|
+// Method[] methods = aClass.getMethods();
|
|
|
|
+//
|
|
|
|
+// FanMainSgt fanMainSgt = new FanMainSgt();
|
|
|
|
+// Class<? extends FanMainSgt> aClass1 = fanMainSgt.getClass();
|
|
|
|
+// Field[] fields = aClass1.getDeclaredFields();
|
|
|
|
+//
|
|
|
|
+// for(Method method:methods){
|
|
|
|
+// String name = method.getName();
|
|
|
|
+// for(Field field:fields){
|
|
|
|
+// if(name.equals(field.getName())){
|
|
|
|
+// String type = field.getType().getSimpleName();
|
|
|
|
+// for(PLCDevice2Enum.FanMainSgtEnum enn:values){
|
|
|
|
+// if(name.equals(enn.getName())){
|
|
|
|
+// String message = PLCDevice2Enum.FanMainSgtEnum.valueOf("FAN_MAIN_SGT_ENUM_"+enn.getName().toUpperCase()).getMessage();
|
|
|
|
+// System.out.println("参数名: "+name+" 类型: "+type+" 说明: "+message);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+}
|