From 4c696eb19609cf3aacdfdd8177c7e7353aaf1d6d Mon Sep 17 00:00:00 2001 From: wangliwen Date: Fri, 15 Jul 2022 12:00:29 +0800 Subject: [PATCH] ... --- .../common/utils/CodeGenerationUtils.java | 68 ++++--------------- 1 file changed, 12 insertions(+), 56 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/common/utils/CodeGenerationUtils.java b/renren-admin/src/main/java/io/renren/common/utils/CodeGenerationUtils.java index b56c6888..1edd1d4f 100644 --- a/renren-admin/src/main/java/io/renren/common/utils/CodeGenerationUtils.java +++ b/renren-admin/src/main/java/io/renren/common/utils/CodeGenerationUtils.java @@ -42,7 +42,7 @@ public class CodeGenerationUtils { /** - * 生成流程单号 + * 设置流程单号 *

* 流程单号编码规则: * 流程类型大写首字母 + 年月日 + 四位流水号 @@ -51,57 +51,6 @@ public class CodeGenerationUtils { * @param type 流程类型首字母(大写) * @return 流程单号 */ -// public String getApplyNumber(String type) { -// -// String applyNumberPattern = type + SIMPLE_DATE_FORMAT.format(new Date()); -// -// if (StringUtils.isBlank(type)) { -// return ""; -// } -// switch (type) { -// //能力上架 -// case "NLSJ": -// return getApplyNumberString("t_resource_mount_apply", applyNumberPattern); -// -// //能力使用 -// case "NLSY": -// return getApplyNumberString("t_ability_application", applyNumberPattern); -// -// //能力需求 -// case "NLXQ": -// return getApplyNumberString("t_demand_data", applyNumberPattern); -// -// //需求评论 -// case "XQPL": -// return getApplyNumberString("t_demand_comment", applyNumberPattern); -// -// //能力下架 -// case "NLXJ": -// return getApplyNumberString("tb_data_resource", applyNumberPattern); -// -// default: -// return ""; -// } -// } -// -// private String getApplyNumberString(String tableName, String applyNumberPattern) { -// lock.lock(); -// String sql = "SELECT SUBSTR(apply_number, 5) FROM " + tableName + -// " WHERE 1 = 1 AND apply_number IS NOT NULL " + -// "AND apply_number LIKE '" + applyNumberPattern + "%' " + -// "ORDER BY apply_number DESC " + -// "LIMIT 1"; -// logger.info(sql); -// try { -// String s = jdbcTemplate.queryForObject(sql, String.class); -// return applyNumberPattern.substring(0, 3) + (Long.parseLong(s) + 1); -// } catch (Exception e) { -// logger.error("流水号生成失败", e); -// return applyNumberPattern + "0001"; -// } finally { -// lock.unlock(); -// } -// } public void setApplyNumber(String type, final String id, final JdbcTemplate jdbcTemplate) { String applyNumberPattern = type + SIMPLE_DATE_FORMAT.format(new Date()); if (StringUtils.isBlank(type)) { @@ -110,6 +59,9 @@ public class CodeGenerationUtils { if (StringUtils.isEmpty(id)) { return; } + if (jdbcTemplate == null) { + return; + } String tableName = null; switch (type) { //能力上架 @@ -143,14 +95,18 @@ public class CodeGenerationUtils { String no = null; try { String s = jdbcTemplate.queryForObject(sql, String.class); - no = applyNumberPattern.substring(0, 3) + (Long.parseLong(s) + 1); + no = applyNumberPattern.substring(0, 4) + (Long.parseLong(s) + 1); } catch (Exception e) { logger.error("流水号生成失败", e); no = applyNumberPattern + "0001"; } finally { - String sql_ = String.format("UPDATE %s SET apply_number = '%s' WHERE id = %s;", tableName, no, id); - logger.info(sql_); - jdbcTemplate.update(sql_); + try { + String sql_ = String.format("UPDATE %s SET apply_number = '%s' WHERE id = %s;", tableName, no, id); + logger.info(sql_); + jdbcTemplate.update(sql_); + } catch (Exception exception) { + logger.error("流水号写入失败", exception); + } lock.unlock(); } }