|
@@ -1233,6 +1233,9 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
|
|
|
String delSql = "delete from " + tabName + " where p_key_id=" + tableInfo.getPkeyId();
|
|
|
String sqlInfo = "";
|
|
|
LinkedHashMap<String, String> dataMap2 = tableInfo.getDataMap();
|
|
|
+ if (!updateFieldLength(tabName, dataMap2)) {
|
|
|
+ throw new ServiceException("字段长度超出限制, 系统无法进行自增,请前往后台管理系统手动设置");
|
|
|
+ }
|
|
|
/*检查发现有p_key_id缺失的情况,导致表单数据丢失,所以强制覆盖*/
|
|
|
dataMap2.put("p_key_id", tableInfo.getPkeyId());
|
|
|
//统计保存的字段
|
|
@@ -1342,6 +1345,58 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
|
|
|
// return R.success(fileName1);
|
|
|
}
|
|
|
|
|
|
+ public boolean updateFieldLength(String tableName, Map<String, String> fieldNameAndLengthMap) {
|
|
|
+ if (fieldNameAndLengthMap == null || fieldNameAndLengthMap.isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ fieldNameAndLengthMap.remove("id");
|
|
|
+ fieldNameAndLengthMap.remove("p_key_id");
|
|
|
+ fieldNameAndLengthMap.remove("group_id");
|
|
|
+ if (fieldNameAndLengthMap.isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String fields = fieldNameAndLengthMap.keySet().stream().map(key -> "'" + key + "'").collect(Collectors.joining(","));
|
|
|
+ List<Map<String, Object>> fieldMap = jdbcTemplate.queryForList("select distinct COLUMN_NAME as fieldName, CHARACTER_MAXIMUM_LENGTH as fieldLength from information_schema.COLUMNS where TABLE_NAME = '" + tableName +
|
|
|
+ "' and COLUMN_NAME in (" + fields + ")");
|
|
|
+ Map<String, Integer> map = fieldMap.stream().collect(toMap(k -> k.get("fieldName") + "", v -> {
|
|
|
+ if (v.get("fieldLength") == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return Integer.parseInt(v.get("fieldLength") + "");
|
|
|
+ }, Math::max));
|
|
|
+
|
|
|
+ List<WbsFormElement> elementList = jdbcTemplate.query("SELECT id,e_key,e_length from m_wbs_form_element WHERE f_id = (SELECT id from m_table_info WHERE tab_en_name = '" + tableName
|
|
|
+ +"' and is_deleted = 0 limit 1) and is_deleted = 0 and e_key in ( " + fields + ")", new BeanPropertyRowMapper<>(WbsFormElement.class));
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
+ sql.append("alter table ").append(tableName);
|
|
|
+ elementList.forEach(element -> {
|
|
|
+ String data = fieldNameAndLengthMap.get(element.getEKey());
|
|
|
+ if (data != null && element.getELength() != null && data.length() > element.getELength()) {
|
|
|
+ int length = data.length();
|
|
|
+ // 取整
|
|
|
+ length = (length / 10 + 1) * 10;
|
|
|
+ Integer fieldLength = map.get(element.getEKey());
|
|
|
+ if (fieldLength != null && fieldLength < element.getELength()) {
|
|
|
+ element.setELength(length);
|
|
|
+ sql.append(" modify column ").append(element.getEKey()).append(" ").append("varchar").append("(").append(length).append("),");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (sql.indexOf("modify") > 0) {
|
|
|
+ TransactionStatus transactionStatus = this.beginTransaction(transactionManager1);
|
|
|
+ try {
|
|
|
+ jdbcTemplate.batchUpdate("update m_wbs_form_element set e_length = ? where id = ?", elementList.stream().map(element -> new Object[]{element.getELength(), element.getId()}).collect(Collectors.toList()));
|
|
|
+ jdbcTemplate.execute(sql.toString());
|
|
|
+ transactionManager1.commit(transactionStatus);
|
|
|
+ } catch (Exception e) {
|
|
|
+ transactionManager1.rollback(transactionStatus);
|
|
|
+ log.error("更新字段长度失败, error: " + e.getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
public String reason(String log) {
|
|
|
/*保存的时候错误提示例如:字段过短提示 yangyj*/
|
|
|
StringBuilder sb = new StringBuilder();
|