insertData界面调整

This commit is contained in:
huliang 2025-03-24 23:54:26 +08:00
parent 492eb5292b
commit 01bbf3e70c
5 changed files with 105 additions and 294 deletions

View File

@ -8,40 +8,16 @@ import javax.baja.sys.*;
* Created by Huliang and jiahao on 2025/03/05.
*/
@NiagaraType
@NiagaraProperty(name = "insertToDatabase", type = "boolean", defaultValue = "true",flags =Flags.SUMMARY )
//@NiagaraProperty(name = "insertToDatabase", type = "boolean", defaultValue = "true",flags =Flags.SUMMARY )
@NiagaraProperty(name = "dbIp", type = "BString", defaultValue = "127.0.0.1",flags =Flags.SUMMARY )
@NiagaraProperty(name = "dbName", type = "BString", defaultValue = "center",flags =Flags.SUMMARY )
@NiagaraProperty(name = "dbUser", type = "BString", defaultValue = "sa",flags =Flags.SUMMARY )
@NiagaraProperty(name = "dbPassword", type = "BString", defaultValue = "123456",flags =Flags.SUMMARY )
@NiagaraProperty(name = "dbTableName", type = "BString", defaultValue = "",flags =Flags.SUMMARY )
public class BDatabaseInformation extends BComponent {
/*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/
/*@ $com.mjm.solarInsertDB.BDatabaseInformation(371321780)1.0$ @*/
/* Generated Fri Mar 07 22:03:14 CST 2025 by Slot-o-Matic (c) Tridium, Inc. 2012 */
////////////////////////////////////////////////////////////////
// Property "insertToDatabase"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code insertToDatabase} property.
* @see #getInsertToDatabase
* @see #setInsertToDatabase
*/
public static final Property insertToDatabase = newProperty(Flags.SUMMARY, true, null);
/**
* Get the {@code insertToDatabase} property.
* @see #insertToDatabase
*/
public boolean getInsertToDatabase() { return getBoolean(insertToDatabase); }
/**
* Set the {@code insertToDatabase} property.
* @see #insertToDatabase
*/
public void setInsertToDatabase(boolean v) { setBoolean(insertToDatabase, v, null); }
/*@ $com.mjm.solarInsertDB.BDatabaseInformation(1329227581)1.0$ @*/
/* Generated Mon Mar 24 23:40:56 CST 2025 by Slot-o-Matic (c) Tridium, Inc. 2012 */
////////////////////////////////////////////////////////////////
// Property "dbIp"
@ -168,6 +144,8 @@ public class BDatabaseInformation extends BComponent {
/*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/
public void changed(Property property, Context context) {
if (this.isRunning()) {
System.out.println("DB information changed");

View File

@ -23,11 +23,11 @@ import java.util.*;
{
@NiagaraProperty(name = "DatabaseInformation", type = "BDatabaseInformation", defaultValue = "new BDatabaseInformation()", flags = Flags.SUMMARY),
@NiagaraProperty(name = "disable", type = "boolean", defaultValue = "true", flags = Flags.SUMMARY),
@NiagaraProperty(name = "exception", type = "boolean", defaultValue = "false", flags = Flags.SUMMARY),
@NiagaraProperty(name = "working", type = "boolean", defaultValue = "false", flags = Flags.SUMMARY),
// @NiagaraProperty(name = "exception", type = "boolean", defaultValue = "false", flags = Flags.SUMMARY),
// @NiagaraProperty(name = "working", type = "boolean", defaultValue = "false", flags = Flags.SUMMARY),
@NiagaraProperty(name = "showMessage", type = "boolean", defaultValue = "true", flags = Flags.SUMMARY),
@NiagaraProperty(name = "path", type = "String", defaultValue = "", flags = Flags.SUMMARY),
@NiagaraProperty(name = "fileName", type = "String", defaultValue = "", flags = Flags.SUMMARY)
// @NiagaraProperty(name = "path", type = "String", defaultValue = "", flags = Flags.SUMMARY),
// @NiagaraProperty(name = "fileName", type = "String", defaultValue = "", flags = Flags.SUMMARY)
},
actions =
{
@ -38,272 +38,121 @@ import java.util.*;
public class BInsertData extends BComponent {
/*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/
/*@ $com.mjm.solarInsertDB.BInsertData(1564231253)1.0$ @*/
/* Generated Fri Mar 07 22:21:47 CST 2025 by Slot-o-Matic (c) Tridium, Inc. 2012 */
/*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/
/*@ $com.mjm.solarInsertDB.BInsertData(1868318216)1.0$ @*/
/* Generated Mon Mar 24 23:40:57 CST 2025 by Slot-o-Matic (c) Tridium, Inc. 2012 */
////////////////////////////////////////////////////////////////
// Property "DatabaseInformation"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code DatabaseInformation} property.
*
* @see #getDatabaseInformation
* @see #setDatabaseInformation
*/
public static final Property DatabaseInformation = newProperty(Flags.SUMMARY, new BDatabaseInformation(), null);
/**
* Get the {@code DatabaseInformation} property.
*
* @see #DatabaseInformation
*/
public BDatabaseInformation getDatabaseInformation() {
return (BDatabaseInformation) get(DatabaseInformation);
}
/**
* Set the {@code DatabaseInformation} property.
*
* @see #DatabaseInformation
*/
public void setDatabaseInformation(BDatabaseInformation v) {
set(DatabaseInformation, v, null);
}
/**
* Slot for the {@code DatabaseInformation} property.
* @see #getDatabaseInformation
* @see #setDatabaseInformation
*/
public static final Property DatabaseInformation = newProperty(Flags.SUMMARY, new BDatabaseInformation(), null);
/**
* Get the {@code DatabaseInformation} property.
* @see #DatabaseInformation
*/
public BDatabaseInformation getDatabaseInformation() { return (BDatabaseInformation)get(DatabaseInformation); }
/**
* Set the {@code DatabaseInformation} property.
* @see #DatabaseInformation
*/
public void setDatabaseInformation(BDatabaseInformation v) { set(DatabaseInformation, v, null); }
////////////////////////////////////////////////////////////////
// Property "disable"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code disable} property.
*
* @see #getDisable
* @see #setDisable
*/
public static final Property disable = newProperty(Flags.SUMMARY, true, null);
/**
* Get the {@code disable} property.
*
* @see #disable
*/
public boolean getDisable() {
return getBoolean(disable);
}
/**
* Set the {@code disable} property.
*
* @see #disable
*/
public void setDisable(boolean v) {
setBoolean(disable, v, null);
}
////////////////////////////////////////////////////////////////
// Property "exception"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code exception} property.
*
* @see #getException
* @see #setException
*/
public static final Property exception = newProperty(Flags.SUMMARY, false, null);
/**
* Get the {@code exception} property.
*
* @see #exception
*/
public boolean getException() {
return getBoolean(exception);
}
/**
* Set the {@code exception} property.
*
* @see #exception
*/
public void setException(boolean v) {
setBoolean(exception, v, null);
}
////////////////////////////////////////////////////////////////
// Property "working"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code working} property.
*
* @see #getWorking
* @see #setWorking
*/
public static final Property working = newProperty(Flags.SUMMARY, false, null);
/**
* Get the {@code working} property.
*
* @see #working
*/
public boolean getWorking() {
return getBoolean(working);
}
/**
* Set the {@code working} property.
*
* @see #working
*/
public void setWorking(boolean v) {
setBoolean(working, v, null);
}
/**
* Slot for the {@code disable} property.
* @see #getDisable
* @see #setDisable
*/
public static final Property disable = newProperty(Flags.SUMMARY, true, null);
/**
* Get the {@code disable} property.
* @see #disable
*/
public boolean getDisable() { return getBoolean(disable); }
/**
* Set the {@code disable} property.
* @see #disable
*/
public void setDisable(boolean v) { setBoolean(disable, v, null); }
////////////////////////////////////////////////////////////////
// Property "showMessage"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code showMessage} property.
*
* @see #getShowMessage
* @see #setShowMessage
*/
public static final Property showMessage = newProperty(Flags.SUMMARY, true, null);
/**
* Get the {@code showMessage} property.
*
* @see #showMessage
*/
public boolean getShowMessage() {
return getBoolean(showMessage);
}
/**
* Set the {@code showMessage} property.
*
* @see #showMessage
*/
public void setShowMessage(boolean v) {
setBoolean(showMessage, v, null);
}
////////////////////////////////////////////////////////////////
// Property "path"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code path} property.
*
* @see #getPath
* @see #setPath
*/
public static final Property path = newProperty(Flags.SUMMARY, "", null);
/**
* Get the {@code path} property.
*
* @see #path
*/
public String getPath() {
return getString(path);
}
/**
* Set the {@code path} property.
*
* @see #path
*/
public void setPath(String v) {
setString(path, v, null);
}
////////////////////////////////////////////////////////////////
// Property "fileName"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code fileName} property.
*
* @see #getFileName
* @see #setFileName
*/
public static final Property fileName = newProperty(Flags.SUMMARY, "", null);
/**
* Get the {@code fileName} property.
*
* @see #fileName
*/
public String getFileName() {
return getString(fileName);
}
/**
* Set the {@code fileName} property.
*
* @see #fileName
*/
public void setFileName(String v) {
setString(fileName, v, null);
}
/**
* Slot for the {@code showMessage} property.
* @see #getShowMessage
* @see #setShowMessage
*/
public static final Property showMessage = newProperty(Flags.SUMMARY, true, null);
/**
* Get the {@code showMessage} property.
* @see #showMessage
*/
public boolean getShowMessage() { return getBoolean(showMessage); }
/**
* Set the {@code showMessage} property.
* @see #showMessage
*/
public void setShowMessage(boolean v) { setBoolean(showMessage, v, null); }
////////////////////////////////////////////////////////////////
// Action "insert"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code insert} action.
*
* @see #insert()
*/
public static final Action insert = newAction(0, null);
/**
* Invoke the {@code insert} action.
*
* @see #insert
*/
public void insert() {
invoke(insert, null, null);
}
/**
* Slot for the {@code insert} action.
* @see #insert()
*/
public static final Action insert = newAction(0, null);
/**
* Invoke the {@code insert} action.
* @see #insert
*/
public void insert() { invoke(insert, null, null); }
////////////////////////////////////////////////////////////////
// Action "setField"
////////////////////////////////////////////////////////////////
/**
* Slot for the {@code setField} action.
*
* @see #setField(BInteger parameter)
*/
public static final Action setField = newAction(0, BInteger.make(1), null);
/**
* Invoke the {@code setField} action.
*
* @see #setField
*/
public void setField(BInteger parameter) {
invoke(setField, parameter, null);
}
/**
* Slot for the {@code setField} action.
* @see #setField(BInteger parameter)
*/
public static final Action setField = newAction(0, BInteger.make(1), null);
/**
* Invoke the {@code setField} action.
* @see #setField
*/
public void setField(BInteger parameter) { invoke(setField, parameter, null); }
////////////////////////////////////////////////////////////////
// Type
////////////////////////////////////////////////////////////////
@Override
public Type getType() { return TYPE; }
public static final Type TYPE = Sys.loadType(BInsertData.class);
@Override
public Type getType() {
return TYPE;
}
/*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/
public static final Type TYPE = Sys.loadType(BInsertData.class);
/*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/
BDatabaseInformation databaseInformation = null;
@ -327,18 +176,17 @@ public class BInsertData extends BComponent {
public void doInsert() {
System.out.println("0323 doInsert: ");
System.out.println("0324 doInsert: ");
if (1 == 1) { //if (checkLicense.getLegal())
List<String> fieldName = new ArrayList<String>();
List<String> fieldValue = new ArrayList<String>();
if (this.getDisable() || this.getException()) {
if (this.getDisable() ) {
if (this.getShowMessage()) {
System.out.println("disable or exception");
System.out.println("disable ");
}
} else {
try {
this.setWorking(true);
Property property[] = this.getDynamicPropertiesArray();
for (int i = 0; i < property.length; i++) {
@ -350,7 +198,6 @@ public class BInsertData extends BComponent {
}
if (fieldName.size() == fieldValue.size()) {
if (databaseInformation.getInsertToDatabase()) {
String insertCommand = makeInsertCommand(fieldName, fieldValue);
// 建立连接
@ -365,15 +212,12 @@ public class BInsertData extends BComponent {
statement.execute(insertCommand);
statement.close();
connection.close();
}
createCSV(fieldName, fieldValue);
}
} catch (Exception e) {
System.out.println(e);
this.setException(true);
e.printStackTrace();
} finally {
this.setWorking(false);
}
}
} else {
@ -405,7 +249,7 @@ public class BInsertData extends BComponent {
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String strDate = sdFormat.format(date);
String outputFile = "../../shared/" + this.getPath() + strDate + this.getFileName();
String outputFile = "../../shared/" ;
// before we open the file check to see if it already exists
boolean alreadyExists = new File(outputFile).exists();
@ -413,15 +257,6 @@ public class BInsertData extends BComponent {
// use FileWriter constructor that specifies open for appending
if (!alreadyExists) {
deleteFile();
if (!this.getPath().equals("")) {
File file = new File(outputFile);
file.getParentFile().mkdir();
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');
@ -458,7 +293,7 @@ public class BInsertData extends BComponent {
Date sDate = sdf.parse(before90);
long beforeTimestamp = sDate.getTime() / 1000;
// System.out.println(beforeTimestamp);
String fullpath = "../../shared/" + this.getPath();
String fullpath = "../../shared/";
File a = new File(fullpath);
if (a.isDirectory()) {
String[] filenames = a.list();

View File

@ -315,7 +315,7 @@ public class BInsertData2 extends BComponent {
if (fieldName.size() == fieldValue.size()) {
// System.out.println(databaseInformation.getInsertToDatabase());
if (databaseInformation.getInsertToDatabase()) {
String insertCommand = makeInsertCommand(fieldName, fieldValue);
// System.out.println("insertCommand : "+insertCommand);
// ConnectInformation connectInformation = new ConnectInformation(databaseInformation.getDbIp(), databaseInformation.getDbName(), databaseInformation.getDbUser(), databaseInformation.getDbPassword(), databaseInformation.getDbTableName());
@ -335,7 +335,7 @@ public class BInsertData2 extends BComponent {
statement.execute(insertCommand);
statement.close();
connection.close();
}
createCSV(fieldName, fieldValue);

View File

@ -302,7 +302,6 @@ public class BUpdateData extends BComponent {
}
if (fieldName.size() == fieldValue.size() && conditionName.size() == conditionValue.size()) {
if (databaseInformation.getInsertToDatabase()) {
// String updateCommand = makeUpdateCommand(fieldName, fieldValue,conditionName,conditionValue);
String updateCommand = makeUpdateCommand2(fieldName, fieldValue);
// 建立连接
@ -317,7 +316,6 @@ public class BUpdateData extends BComponent {
statement.execute(updateCommand);
statement.close();
connection.close();
}
createCSV(fieldName, fieldValue);
}
} catch (Exception e) {