|
|
@@ -108,16 +108,465 @@ public class JdbcUtils {
|
|
|
String configRecord2 = "CREATE TABLE if not exists task(\n" +
|
|
|
" id INTEGER PRIMARY KEY AUTOINCREMENT, -- 自增ID\n" +
|
|
|
" title VARCHAR(255), -- 任务名称\n" +
|
|
|
- " cate VARCHAR(1), -- 任务类型 1=左工位 2=右工位\n" +
|
|
|
+ " cate VARCHAR(1), -- 任务类型 0=左工位 1=右工位\n" +
|
|
|
" barcode_spec VARCHAR(255), -- 条码固定位\n" +
|
|
|
" barcode_spec_start VARCHAR(20), -- 固定位起始位数\n" +
|
|
|
" barcode_length VARCHAR(50), -- 条码长度\n" +
|
|
|
" content VARCHAR(5000) -- 配置内容,json格式 \n" +
|
|
|
")";
|
|
|
statement.executeUpdate(configRecord2);
|
|
|
+ // 兼容从 qm 拷来的旧库:task 表可能没有 cate 列
|
|
|
+ if (!hasColumn("task", "cate")) {
|
|
|
+ tryAlter("ALTER TABLE task ADD COLUMN cate VARCHAR(1)");
|
|
|
+ try {
|
|
|
+ statement.executeUpdate("UPDATE task SET cate='0' WHERE IFNULL(cate,'')=''");
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ }
|
|
|
+ log.info("已为 task 表补齐 cate 列(旧任务默认左工位)");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ statement.executeUpdate("ALTER TABLE test_record ADD COLUMN upload_status VARCHAR(1) DEFAULT '0'");
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ statement.executeUpdate("ALTER TABLE test_record ADD COLUMN upload_retry INT DEFAULT 0");
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ }
|
|
|
+
|
|
|
+ String appConfig = "CREATE TABLE if not exists app_config("
|
|
|
+ + "cfg_key VARCHAR(64) PRIMARY KEY,"
|
|
|
+ + "cfg_value VARCHAR(128)"
|
|
|
+ + ")";
|
|
|
+ statement.executeUpdate(appConfig);
|
|
|
+ ensureConfigDefault("seal_ring_limit", "200");
|
|
|
+ ensureConfigDefault("seal_ring_count", "0");
|
|
|
+ // 左右工位胶圈独立;若有旧全局值则继承到左侧
|
|
|
+ String legacyLimit = getAppConfig("seal_ring_limit", "200");
|
|
|
+ String legacyCount = getAppConfig("seal_ring_count", "0");
|
|
|
+ ensureConfigDefault("seal_ring_limit_L", legacyLimit);
|
|
|
+ ensureConfigDefault("seal_ring_limit_R", legacyLimit);
|
|
|
+ ensureConfigDefault("seal_ring_count_L", legacyCount);
|
|
|
+ ensureConfigDefault("seal_ring_count_R", "0");
|
|
|
+ ensureConfigDefault("leak_check_ok_time", "");
|
|
|
+ ensureConfigDefault("leak_check_ok_time_L", "");
|
|
|
+ ensureConfigDefault("leak_check_ok_time_R", "");
|
|
|
+
|
|
|
+ String leakCheckRecord = "CREATE TABLE if not exists leak_check_record(\n" +
|
|
|
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
|
|
|
+ " sn VARCHAR(48),\n" +
|
|
|
+ " ucode VARCHAR(48),\n" +
|
|
|
+ " line_sn VARCHAR(48),\n" +
|
|
|
+ " oprno VARCHAR(48),\n" +
|
|
|
+ " oprno_title VARCHAR(48),\n" +
|
|
|
+ " create_time DATETIME,\n" +
|
|
|
+ " pressure VARCHAR(48),\n" +
|
|
|
+ " pressure_unit VARCHAR(48),\n" +
|
|
|
+ " leak VARCHAR(48),\n" +
|
|
|
+ " leak_unit VARCHAR(48),\n" +
|
|
|
+ " program_no VARCHAR(48),\n" +
|
|
|
+ " result VARCHAR(48),\n" +
|
|
|
+ " remark VARCHAR(48),\n" +
|
|
|
+ " device_type VARCHAR(48),\n" +
|
|
|
+ " upload_status VARCHAR(1) DEFAULT '0',\n" +
|
|
|
+ " upload_retry INT DEFAULT 0\n" +
|
|
|
+ ")";
|
|
|
+ statement.executeUpdate(leakCheckRecord);
|
|
|
+
|
|
|
+ // 兼容 mesclient-qm 旧库(param1~param5),迁移后可直接读历史
|
|
|
+ ensureQmLegacySchemaCompat();
|
|
|
|
|
|
statement.close();
|
|
|
}
|
|
|
+
|
|
|
+ /** qm 旧表字段 param1~5 ↔ qm2 的 pressure/leak/program_no */
|
|
|
+ private static void ensureQmLegacySchemaCompat() {
|
|
|
+ migrateParamColumnsToPressure("test_record");
|
|
|
+ migrateParamColumnsToPressure("leak_check_record");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void migrateParamColumnsToPressure(String table) {
|
|
|
+ try {
|
|
|
+ boolean hasParam1 = hasColumn(table, "param1");
|
|
|
+ boolean hasPressure = hasColumn(table, "pressure");
|
|
|
+ if (!hasPressure) {
|
|
|
+ tryAlter("ALTER TABLE " + table + " ADD COLUMN pressure VARCHAR(48)");
|
|
|
+ tryAlter("ALTER TABLE " + table + " ADD COLUMN pressure_unit VARCHAR(48)");
|
|
|
+ tryAlter("ALTER TABLE " + table + " ADD COLUMN leak VARCHAR(48)");
|
|
|
+ tryAlter("ALTER TABLE " + table + " ADD COLUMN leak_unit VARCHAR(48)");
|
|
|
+ tryAlter("ALTER TABLE " + table + " ADD COLUMN program_no VARCHAR(48)");
|
|
|
+ hasPressure = true;
|
|
|
+ }
|
|
|
+ if (hasParam1 && hasPressure) {
|
|
|
+ Statement st = conn.createStatement();
|
|
|
+ int n = st.executeUpdate(
|
|
|
+ "UPDATE " + table + " SET "
|
|
|
+ + "pressure=CASE WHEN IFNULL(pressure,'')='' THEN param1 ELSE pressure END, "
|
|
|
+ + "pressure_unit=CASE WHEN IFNULL(pressure_unit,'')='' THEN param2 ELSE pressure_unit END, "
|
|
|
+ + "leak=CASE WHEN IFNULL(leak,'')='' THEN param3 ELSE leak END, "
|
|
|
+ + "leak_unit=CASE WHEN IFNULL(leak_unit,'')='' THEN param4 ELSE leak_unit END, "
|
|
|
+ + "program_no=CASE WHEN IFNULL(program_no,'')='' THEN param5 ELSE program_no END "
|
|
|
+ + "WHERE IFNULL(param1,'')<>'' OR IFNULL(param3,'')<>'' OR IFNULL(param5,'')<>''");
|
|
|
+ st.close();
|
|
|
+ if (n > 0) {
|
|
|
+ log.info("已从 qm 旧字段迁移 {} 条到 {}.(pressure/leak)", n, table);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("兼容迁移 {} 失败: {}", table, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void tryAlter(String sql) {
|
|
|
+ try {
|
|
|
+ Statement st = conn.createStatement();
|
|
|
+ st.executeUpdate(sql);
|
|
|
+ st.close();
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean hasColumn(String table, String column) {
|
|
|
+ try {
|
|
|
+ Statement st = conn.createStatement();
|
|
|
+ ResultSet rs = st.executeQuery("PRAGMA table_info(" + table + ")");
|
|
|
+ while (rs.next()) {
|
|
|
+ if (column.equalsIgnoreCase(rs.getString("name"))) {
|
|
|
+ rs.close();
|
|
|
+ st.close();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ st.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("检查列 {}.{} 失败: {}", table, column, e.getMessage());
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 优先读新字段,没有则回退 qm 旧字段 param* */
|
|
|
+ private static String getCompatCol(ResultSet rs, String modern, String legacy) {
|
|
|
+ try {
|
|
|
+ String v = rs.getString(modern);
|
|
|
+ if (v != null) {
|
|
|
+ return v;
|
|
|
+ }
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String v = rs.getString(legacy);
|
|
|
+ return v == null ? "" : v;
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void ensureConfigDefault(String key, String defaultValue) {
|
|
|
+ try {
|
|
|
+ if (conn == null || conn.isClosed()) {
|
|
|
+ openConnection();
|
|
|
+ }
|
|
|
+ PreparedStatement ps = conn.prepareStatement("SELECT cfg_value FROM app_config WHERE cfg_key=?");
|
|
|
+ ps.setString(1, key);
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
+ boolean exists = rs.next();
|
|
|
+ rs.close();
|
|
|
+ ps.close();
|
|
|
+ if (!exists) {
|
|
|
+ PreparedStatement ins = conn.prepareStatement("INSERT INTO app_config(cfg_key,cfg_value) VALUES(?,?)");
|
|
|
+ ins.setString(1, key);
|
|
|
+ ins.setString(2, defaultValue);
|
|
|
+ ins.executeUpdate();
|
|
|
+ ins.close();
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("初始化配置失败 key={}", key, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getAppConfig(String key, String defaultValue) {
|
|
|
+ try {
|
|
|
+ if (conn == null || conn.isClosed()) {
|
|
|
+ openConnection();
|
|
|
+ }
|
|
|
+ PreparedStatement ps = conn.prepareStatement("SELECT cfg_value FROM app_config WHERE cfg_key=?");
|
|
|
+ ps.setString(1, key);
|
|
|
+ ResultSet rs = ps.executeQuery();
|
|
|
+ String value = defaultValue;
|
|
|
+ if (rs.next()) {
|
|
|
+ value = rs.getString(1);
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ ps.close();
|
|
|
+ return value == null || value.trim().isEmpty() ? defaultValue : value.trim();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("读取配置失败 key={}", key, e);
|
|
|
+ return defaultValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setAppConfig(String key, String value) {
|
|
|
+ try {
|
|
|
+ if (conn == null || conn.isClosed()) {
|
|
|
+ openConnection();
|
|
|
+ }
|
|
|
+ PreparedStatement ps = conn.prepareStatement(
|
|
|
+ "INSERT OR REPLACE INTO app_config(cfg_key,cfg_value) VALUES(?,?)");
|
|
|
+ ps.setString(1, key);
|
|
|
+ ps.setString(2, value);
|
|
|
+ ps.executeUpdate();
|
|
|
+ ps.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("保存配置失败 key={}", key, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String sealRingSideKey(String prefix, int side) {
|
|
|
+ return prefix + (side == 1 ? "_R" : "_L");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getSealRingLimit(int side) {
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(getAppConfig(sealRingSideKey("seal_ring_limit", side), "200"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ return 200;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getSealRingCount(int side) {
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(getAppConfig(sealRingSideKey("seal_ring_count", side), "0"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setSealRingLimit(int side, int limit) {
|
|
|
+ setAppConfig(sealRingSideKey("seal_ring_limit", side), String.valueOf(Math.max(1, limit)));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int incrementSealRingCount(int side) {
|
|
|
+ int count = getSealRingCount(side) + 1;
|
|
|
+ setAppConfig(sealRingSideKey("seal_ring_count", side), String.valueOf(count));
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void resetSealRingCount(int side) {
|
|
|
+ setAppConfig(sealRingSideKey("seal_ring_count", side), "0");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请使用带 side 的重载 */
|
|
|
+ public static int getSealRingLimit() {
|
|
|
+ return getSealRingLimit(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请使用带 side 的重载 */
|
|
|
+ public static int getSealRingCount() {
|
|
|
+ return getSealRingCount(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请使用带 side 的重载 */
|
|
|
+ public static void setSealRingLimit(int limit) {
|
|
|
+ setSealRingLimit(0, limit);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请使用带 side 的重载 */
|
|
|
+ public static int incrementSealRingCount() {
|
|
|
+ return incrementSealRingCount(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请使用带 side 的重载 */
|
|
|
+ public static void resetSealRingCount() {
|
|
|
+ resetSealRingCount(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int insertLeakCheckRecordReturnId(TestParam testParam) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ String insertSQL = "INSERT INTO leak_check_record (oprno,oprno_title,ucode, sn, line_sn, create_time, pressure, pressure_unit, leak, leak_unit, program_no, result, remark, device_type, upload_status, upload_retry)" +
|
|
|
+ "VALUES('" + testParam.getOprno() + "','" + testParam.getOprnoTitle() + "','" + testParam.getUcode() + "', '" + testParam.getSn() + "', '" + testParam.getLineSn() + "', '" + testParam.getCreateTime() + "', '" + testParam.getPressure() + "', '"
|
|
|
+ + testParam.getPressureUnit() + "','" + testParam.getLeak() + "','" + testParam.getLeakUnit() + "','" + testParam.getProgramNo() + "','" + testParam.getResult() + "','" + testParam.getRemark() + "','" + testParam.getDeviceType() + "','0',0)";
|
|
|
+ statement.executeUpdate(insertSQL);
|
|
|
+ ResultSet rs = statement.executeQuery("SELECT last_insert_rowid()");
|
|
|
+ int id = -1;
|
|
|
+ if (rs.next()) {
|
|
|
+ id = rs.getInt(1);
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ statement.close();
|
|
|
+ log.info("向leak_check_record插入成功, id={}", id);
|
|
|
+ return id;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("向leak_check_record插入失败: {}", e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void updateLeakCheckUploadStatus(int id, String status) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.executeUpdate("UPDATE leak_check_record SET upload_status='" + status + "' WHERE id=" + id);
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("更新leak_check upload_status失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void incrementLeakCheckUploadRetry(int id) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.executeUpdate("UPDATE leak_check_record SET upload_retry=IFNULL(upload_retry,0)+1 WHERE id=" + id);
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("更新leak_check upload_retry失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getLeakCheckUploadRetry(int id) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ ResultSet rs = statement.executeQuery("SELECT upload_retry FROM leak_check_record WHERE id=" + id);
|
|
|
+ if (rs.next()) {
|
|
|
+ return rs.getInt(1);
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("查询leak_check upload_retry失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<TestParam> getPendingLeakCheckUploadRecords(int limit) {
|
|
|
+ List<TestParam> list = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ ResultSet rs = statement.executeQuery(
|
|
|
+ "SELECT * FROM leak_check_record WHERE IFNULL(upload_status,'0') != '1' AND IFNULL(upload_retry,0) < 20 ORDER BY id ASC LIMIT " + limit);
|
|
|
+ while (rs.next()) {
|
|
|
+ list.add(mapLeakTestParam(rs));
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("查询待上传标漏记录失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static TestParam mapLeakTestParam(ResultSet rs) throws SQLException {
|
|
|
+ TestParam testParam = new TestParam();
|
|
|
+ testParam.setId(rs.getInt("id"));
|
|
|
+ testParam.setSn(rs.getString("sn"));
|
|
|
+ testParam.setOprno(rs.getString("oprno"));
|
|
|
+ testParam.setOprnoTitle(rs.getString("oprno_title"));
|
|
|
+ testParam.setUcode(rs.getString("ucode"));
|
|
|
+ testParam.setLineSn(rs.getString("line_sn"));
|
|
|
+ testParam.setCreateTime(rs.getString("create_time"));
|
|
|
+ testParam.setPressure(getCompatCol(rs, "pressure", "param1"));
|
|
|
+ testParam.setPressureUnit(getCompatCol(rs, "pressure_unit", "param2"));
|
|
|
+ testParam.setLeak(getCompatCol(rs, "leak", "param3"));
|
|
|
+ testParam.setLeakUnit(getCompatCol(rs, "leak_unit", "param4"));
|
|
|
+ testParam.setProgramNo(getCompatCol(rs, "program_no", "param5"));
|
|
|
+ testParam.setResult(rs.getString("result"));
|
|
|
+ testParam.setRemark(rs.getString("remark"));
|
|
|
+ testParam.setDeviceType(rs.getString("device_type"));
|
|
|
+ return testParam;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 标漏点检记录分页查询 */
|
|
|
+ public static void getLeakCheckData() {
|
|
|
+ if (MesClient.leakRowData == null || MesClient.leakTable == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < MesClient.leakRowData.length; i++) {
|
|
|
+ for (int j = 0; j < MesClient.leakRowData[i].length; j++) {
|
|
|
+ MesClient.leakRowData[i][j] = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int pageSize = 12;
|
|
|
+ int offset = (MesClient.leakPageNo - 1) * pageSize;
|
|
|
+ String keyword = MesClient.leakTextField != null ? MesClient.leakTextField.getText().trim() : "";
|
|
|
+
|
|
|
+ String sql = "SELECT * FROM leak_check_record";
|
|
|
+ String countSql = "select count(*) as total from leak_check_record";
|
|
|
+ if (keyword != null && !keyword.isEmpty()) {
|
|
|
+ sql += " WHERE ucode like '%" + keyword + "%' OR result like '%" + keyword + "%' OR program_no like '%" + keyword + "%'"
|
|
|
+ + " OR create_time like '%" + keyword + "%' OR oprno like '%" + keyword + "%' OR oprno_title like '%" + keyword + "%'";
|
|
|
+ countSql += " WHERE ucode like '%" + keyword + "%' OR result like '%" + keyword + "%' OR program_no like '%" + keyword + "%'"
|
|
|
+ + " OR create_time like '%" + keyword + "%' OR oprno like '%" + keyword + "%' OR oprno_title like '%" + keyword + "%'";
|
|
|
+ }
|
|
|
+ sql += " ORDER BY id DESC LIMIT " + pageSize + " OFFSET " + offset;
|
|
|
+
|
|
|
+ Statement stmt = null;
|
|
|
+ ResultSet ret = null;
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ stmt = conn.createStatement();
|
|
|
+ ResultSet countRet = stmt.executeQuery(countSql);
|
|
|
+ int totalItems = 0;
|
|
|
+ if (countRet.next()) {
|
|
|
+ totalItems = countRet.getInt("total");
|
|
|
+ }
|
|
|
+ countRet.close();
|
|
|
+ if (totalItems == 0) {
|
|
|
+ if (MesClient.leakPageLabel != null) {
|
|
|
+ MesClient.leakPageLabel.setText("0/0");
|
|
|
+ }
|
|
|
+ MesClient.leakTable.repaint();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MesClient.leakTotalPages = (int) Math.ceil(totalItems * 1.0 / pageSize);
|
|
|
+ if (MesClient.leakPageLabel != null) {
|
|
|
+ MesClient.leakPageLabel.setText(MesClient.leakPageNo + "/" + MesClient.leakTotalPages);
|
|
|
+ }
|
|
|
+ ret = stmt.executeQuery(sql);
|
|
|
+ int rowIndex = 0;
|
|
|
+ while (ret.next() && rowIndex < MesClient.leakRowData.length) {
|
|
|
+ String pressure = getCompatCol(ret, "pressure", "param1");
|
|
|
+ String pressureUnit = getCompatCol(ret, "pressure_unit", "param2");
|
|
|
+ String leak = getCompatCol(ret, "leak", "param3");
|
|
|
+ String leakUnit = getCompatCol(ret, "leak_unit", "param4");
|
|
|
+ String oprno = ret.getString("oprno");
|
|
|
+ MesClient.leakRowData[rowIndex][0] = ret.getString("create_time");
|
|
|
+ MesClient.leakRowData[rowIndex][1] = oprno == null ? "" : oprno.trim();
|
|
|
+ MesClient.leakRowData[rowIndex][2] = ret.getString("ucode");
|
|
|
+ MesClient.leakRowData[rowIndex][3] = getCompatCol(ret, "program_no", "param5");
|
|
|
+ MesClient.leakRowData[rowIndex][4] = pressure + pressureUnit;
|
|
|
+ MesClient.leakRowData[rowIndex][5] = leak + leakUnit;
|
|
|
+ MesClient.leakRowData[rowIndex][6] = ret.getString("result");
|
|
|
+ try {
|
|
|
+ MesClient.leakRowData[rowIndex][7] = QmUploadUtil.formatUploadStatus(ret.getString("upload_status"));
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ MesClient.leakRowData[rowIndex][7] = "待上传";
|
|
|
+ }
|
|
|
+ rowIndex++;
|
|
|
+ }
|
|
|
+ MesClient.leakTable.repaint();
|
|
|
+ ret.close();
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//插入数据
|
|
|
public static boolean insertData(String gw, String gy, String bw, String message_type, String sn) {
|
|
|
@@ -191,26 +640,137 @@ public class JdbcUtils {
|
|
|
|
|
|
|
|
|
public static boolean insertTestRecord(TestParam testParam){
|
|
|
- boolean ret = false;
|
|
|
+ return insertTestRecordReturnId(testParam) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int insertTestRecordReturnId(TestParam testParam){
|
|
|
try {
|
|
|
- // 确保连接已经打开
|
|
|
if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
JdbcUtils.openConnection();
|
|
|
}
|
|
|
Statement statement=conn.createStatement();
|
|
|
- String insertSQL = "INSERT INTO test_record (oprno,oprno_title,ucode, sn, line_sn, create_time, pressure, pressure_unit, leak, leak_unit, program_no, result, remark, device_type)" +
|
|
|
+ String insertSQL = "INSERT INTO test_record (oprno,oprno_title,ucode, sn, line_sn, create_time, pressure, pressure_unit, leak, leak_unit, program_no, result, remark, device_type,upload_status,upload_retry)" +
|
|
|
"VALUES('"+testParam.getOprno()+"','" + testParam.getOprnoTitle() + "','"+testParam.getUcode()+"', '" + testParam.getSn() + "', '" + testParam.getLineSn() + "', '" + testParam.getCreateTime() + "', '" + testParam.getPressure()+ "', '"
|
|
|
- +testParam.getPressureUnit()+"','"+testParam.getLeak()+"','"+testParam.getLeakUnit()+"','"+testParam.getProgramNo()+"','"+testParam.getResult()+"','"+testParam.getRemark()+"','"+testParam.getDeviceType()+"')";
|
|
|
+ +testParam.getPressureUnit()+"','"+testParam.getLeak()+"','"+testParam.getLeakUnit()+"','"+testParam.getProgramNo()+"','"+testParam.getResult()+"','"+testParam.getRemark()+"','"+testParam.getDeviceType()+"','0',0)";
|
|
|
statement.executeUpdate(insertSQL);
|
|
|
+ ResultSet rs = statement.executeQuery("SELECT last_insert_rowid()");
|
|
|
+ int id = -1;
|
|
|
+ if (rs.next()) {
|
|
|
+ id = rs.getInt(1);
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
statement.close();
|
|
|
- ret = true;
|
|
|
- log.info("向test_record表插入数据成功: {}", insertSQL);
|
|
|
+ log.info("向test_record表插入数据成功, id={}", id);
|
|
|
+ return id;
|
|
|
} catch (SQLException e) {
|
|
|
- ret = false;
|
|
|
log.error("向test_record表插入数据失败: {}", e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return ret;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void updateUploadStatus(int id, String status) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.executeUpdate("UPDATE test_record SET upload_status='" + status + "' WHERE id=" + id);
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("更新upload_status失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getUploadStatus(int id) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ ResultSet rs = statement.executeQuery("SELECT upload_status FROM test_record WHERE id=" + id);
|
|
|
+ String status = "0";
|
|
|
+ if (rs.next()) {
|
|
|
+ status = rs.getString(1);
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ statement.close();
|
|
|
+ return status == null ? "0" : status;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("读取upload_status失败 id={}", id, e);
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void incrementUploadRetry(int id) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ statement.executeUpdate("UPDATE test_record SET upload_retry=IFNULL(upload_retry,0)+1 WHERE id=" + id);
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("更新upload_retry失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getUploadRetry(int id) {
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ ResultSet rs = statement.executeQuery("SELECT upload_retry FROM test_record WHERE id=" + id);
|
|
|
+ if (rs.next()) {
|
|
|
+ return rs.getInt(1);
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("查询upload_retry失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<TestParam> getPendingUploadRecords(int limit) {
|
|
|
+ List<TestParam> list = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
+ JdbcUtils.openConnection();
|
|
|
+ }
|
|
|
+ Statement statement = conn.createStatement();
|
|
|
+ ResultSet rs = statement.executeQuery(
|
|
|
+ "SELECT * FROM test_record WHERE IFNULL(upload_status,'0') != '1' AND IFNULL(upload_retry,0) < 20 ORDER BY id ASC LIMIT " + limit);
|
|
|
+ while (rs.next()) {
|
|
|
+ list.add(mapTestParam(rs));
|
|
|
+ }
|
|
|
+ rs.close();
|
|
|
+ statement.close();
|
|
|
+ } catch (SQLException e) {
|
|
|
+ log.error("查询待上传记录失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static TestParam mapTestParam(ResultSet rs) throws SQLException {
|
|
|
+ TestParam testParam = new TestParam();
|
|
|
+ testParam.setId(rs.getInt("id"));
|
|
|
+ testParam.setSn(rs.getString("sn"));
|
|
|
+ testParam.setOprno(rs.getString("oprno"));
|
|
|
+ testParam.setOprnoTitle(rs.getString("oprno_title"));
|
|
|
+ testParam.setUcode(rs.getString("ucode"));
|
|
|
+ testParam.setLineSn(rs.getString("line_sn"));
|
|
|
+ testParam.setCreateTime(rs.getString("create_time"));
|
|
|
+ testParam.setPressure(getCompatCol(rs, "pressure", "param1"));
|
|
|
+ testParam.setPressureUnit(getCompatCol(rs, "pressure_unit", "param2"));
|
|
|
+ testParam.setLeak(getCompatCol(rs, "leak", "param3"));
|
|
|
+ testParam.setLeakUnit(getCompatCol(rs, "leak_unit", "param4"));
|
|
|
+ testParam.setProgramNo(getCompatCol(rs, "program_no", "param5"));
|
|
|
+ testParam.setResult(rs.getString("result"));
|
|
|
+ testParam.setRemark(rs.getString("remark"));
|
|
|
+ testParam.setDeviceType(rs.getString("device_type"));
|
|
|
+ return testParam;
|
|
|
}
|
|
|
|
|
|
//面板查询(分页)
|
|
|
@@ -275,15 +835,18 @@ public class JdbcUtils {
|
|
|
|
|
|
|
|
|
while (ret.next()) {
|
|
|
- MesClient.rowData[rowIndex][0] = ret.getString(2);
|
|
|
- MesClient.rowData[rowIndex][1] = ret.getString(4);
|
|
|
- MesClient.rowData[rowIndex][2] = ret.getString(5);
|
|
|
- MesClient.rowData[rowIndex][3] = ret.getString(6)+ret.getString(7);
|
|
|
- MesClient.rowData[rowIndex][4] = ret.getString(8)+ret.getString(9);
|
|
|
- MesClient.rowData[rowIndex][5] = ret.getString(12);
|
|
|
- MesClient.rowData[rowIndex][6] = ret.getString(13);
|
|
|
-// MesClient.rowData[rowIndex][5] = ret.getString(8);
|
|
|
-// MesClient.rowData[rowIndex][6] = ret.getString(9);
|
|
|
+ MesClient.rowData[rowIndex][0] = ret.getString("sn");
|
|
|
+ MesClient.rowData[rowIndex][1] = ret.getString("oprno");
|
|
|
+ MesClient.rowData[rowIndex][2] = ret.getString("oprno_title");
|
|
|
+ MesClient.rowData[rowIndex][3] = ret.getString("create_time");
|
|
|
+ MesClient.rowData[rowIndex][4] = getCompatCol(ret, "pressure", "param1") + getCompatCol(ret, "pressure_unit", "param2");
|
|
|
+ MesClient.rowData[rowIndex][5] = getCompatCol(ret, "leak", "param3") + getCompatCol(ret, "leak_unit", "param4");
|
|
|
+ MesClient.rowData[rowIndex][6] = ret.getString("result");
|
|
|
+ try {
|
|
|
+ MesClient.rowData[rowIndex][7] = QmUploadUtil.formatUploadStatus(ret.getString("upload_status"));
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ MesClient.rowData[rowIndex][7] = "待上传";
|
|
|
+ }
|
|
|
rowIndex++;
|
|
|
}
|
|
|
|
|
|
@@ -308,17 +871,17 @@ public class JdbcUtils {
|
|
|
log.info("selectSql:"+selectSql);
|
|
|
ResultSet rs = statement.executeQuery(selectSql);
|
|
|
while(rs.next()){
|
|
|
- testParam.setSn(rs.getString(2));
|
|
|
- testParam.setOprno(rs.getString(3));
|
|
|
- testParam.setOprnoTitle(rs.getString(4));
|
|
|
- testParam.setCreateTime(rs.getString(5));
|
|
|
- testParam.setPressure(rs.getString(6));
|
|
|
- testParam.setPressureUnit(rs.getString(7));
|
|
|
- testParam.setLeak(rs.getString(8));
|
|
|
- testParam.setLeakUnit(rs.getString(9));
|
|
|
- testParam.setProgramNo(rs.getString(10));
|
|
|
- testParam.setUcode(rs.getString(11));
|
|
|
- testParam.setResult(rs.getString(12));
|
|
|
+ testParam.setSn(rs.getString("sn"));
|
|
|
+ testParam.setOprno(rs.getString("oprno"));
|
|
|
+ testParam.setOprnoTitle(rs.getString("oprno_title"));
|
|
|
+ testParam.setCreateTime(rs.getString("create_time"));
|
|
|
+ testParam.setPressure(getCompatCol(rs, "pressure", "param1"));
|
|
|
+ testParam.setPressureUnit(getCompatCol(rs, "pressure_unit", "param2"));
|
|
|
+ testParam.setLeak(getCompatCol(rs, "leak", "param3"));
|
|
|
+ testParam.setLeakUnit(getCompatCol(rs, "leak_unit", "param4"));
|
|
|
+ testParam.setProgramNo(getCompatCol(rs, "program_no", "param5"));
|
|
|
+ testParam.setUcode(rs.getString("ucode"));
|
|
|
+ testParam.setResult(rs.getString("result"));
|
|
|
}
|
|
|
|
|
|
statement.close();
|
|
|
@@ -415,12 +978,13 @@ public class JdbcUtils {
|
|
|
|
|
|
public static boolean insertTask(TaskParam taskParam){
|
|
|
boolean ret = false;
|
|
|
- String record_time = DateLocalUtils.getCurrentTime();
|
|
|
try {
|
|
|
- // 确保连接已经打开
|
|
|
if (JdbcUtils.conn == null || JdbcUtils.conn.isClosed()) {
|
|
|
JdbcUtils.openConnection();
|
|
|
}
|
|
|
+ if (!hasColumn("task", "cate")) {
|
|
|
+ tryAlter("ALTER TABLE task ADD COLUMN cate VARCHAR(1)");
|
|
|
+ }
|
|
|
Statement statement=conn.createStatement();
|
|
|
|
|
|
TaskConetnt taskConetnt = new TaskConetnt();
|
|
|
@@ -428,14 +992,21 @@ public class JdbcUtils {
|
|
|
taskConetnt.setTaskLeakage(taskParam.getTaskLeakage());
|
|
|
taskConetnt.setTaskLabelName(taskParam.getTaskLabelName());
|
|
|
String content = JSONObject.toJSONString(taskConetnt);
|
|
|
+ String cate = taskParam.getCate() == null ? "0" : taskParam.getCate();
|
|
|
+ String title = taskParam.getTitle() == null ? "" : taskParam.getTitle().replace("'", "''");
|
|
|
+ String barcodeSpec = taskParam.getBarcodeSpec() == null ? "" : taskParam.getBarcodeSpec().replace("'", "''");
|
|
|
+ String barcodeSpecStart = taskParam.getBarcodeSpecStart() == null ? "" : taskParam.getBarcodeSpecStart();
|
|
|
+ String barcodeLength = taskParam.getBarcodeLength() == null ? "" : taskParam.getBarcodeLength();
|
|
|
|
|
|
String insertSQL = "INSERT INTO task (title,cate,barcode_spec,barcode_spec_start,barcode_length,content)"
|
|
|
- + "VALUES('"+taskParam.getTitle()+"','"+taskParam.getCate()+"','"+taskParam.getBarcodeSpec()+"','"+taskParam.getBarcodeSpecStart()+"','"+taskParam.getBarcodeLength()+"','" + content +"')";
|
|
|
+ + "VALUES('"+title+"','"+cate+"','"+barcodeSpec+"','"+barcodeSpecStart+"','"+barcodeLength+"','" + content +"')";
|
|
|
statement.executeUpdate(insertSQL);
|
|
|
statement.close();
|
|
|
ret = true;
|
|
|
+ log.info("新增任务成功: title={}, cate={}", title, cate);
|
|
|
} catch (SQLException e) {
|
|
|
ret = false;
|
|
|
+ log.error("新增任务失败: {}", e.getMessage(), e);
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -516,7 +1087,12 @@ public class JdbcUtils {
|
|
|
taskParam.setBarcodeSpec(rs.getString("barcode_spec"));
|
|
|
taskParam.setBarcodeSpecStart(rs.getString("barcode_spec_start"));
|
|
|
taskParam.setBarcodeLength(rs.getString("barcode_length"));
|
|
|
- taskParam.setCate(rs.getString("cate"));
|
|
|
+ try {
|
|
|
+ String cate = rs.getString("cate");
|
|
|
+ taskParam.setCate(cate == null || cate.isEmpty() ? "0" : cate);
|
|
|
+ } catch (SQLException ignored) {
|
|
|
+ taskParam.setCate("0");
|
|
|
+ }
|
|
|
|
|
|
String content = rs.getString("content");
|
|
|
if(content != null && !content.isEmpty()){
|