|
@@ -27,10 +27,10 @@ import com.boman.web.core.service.save.IBaseSaveService;
|
|
|
import com.boman.web.core.service.select.IBaseSelectService;
|
|
|
import com.boman.web.core.service.submit.IBaseSubmitService;
|
|
|
import com.boman.web.core.service.update.IBaseUpdateService;
|
|
|
-import com.boman.web.core.utils.ColumnUtils;
|
|
|
import com.boman.web.core.utils.IdUtils;
|
|
|
import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -257,41 +257,55 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(rows);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 功能描述: 处理外键
|
|
|
+ *
|
|
|
+ * @param result result
|
|
|
+ * @param columns 该表对应的所有的列
|
|
|
+ */
|
|
|
private void handlerForeignKey(List<JSONObject> result, List<GenTableColumn> columns) {
|
|
|
if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
// 拿到所有有fk的列
|
|
|
- columns = filter(columns, col -> ObjectUtils.isNotEmpty(col.getForeignKey()));
|
|
|
- for (GenTableColumn column : columns) {
|
|
|
+ List<GenTableColumn> fkColumns = filter(columns, col -> ObjectUtils.isNotEmpty(col.getForeignKey()));
|
|
|
+
|
|
|
+ for (GenTableColumn column : fkColumns) {
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
-// Long selfTableId = column.getTableId();
|
|
|
String selfColumnName = column.getColumnName();
|
|
|
for (JSONObject json : result) {
|
|
|
- if (json.containsKey(selfColumnName)) {
|
|
|
- Object value = json.get(selfColumnName);
|
|
|
-
|
|
|
+ if (json.containsKey(selfColumnName.toUpperCase()) || json.containsKey(selfColumnName.toLowerCase())) {
|
|
|
+ // 外键在table_column中的id
|
|
|
Long fkColumnId = Long.parseLong(column.getForeignKey());
|
|
|
GenTableColumn fkTableColumn = remoteGenTableColumnService.getById(fkColumnId);
|
|
|
+ String fkColumnName = fkTableColumn.getColumnName();
|
|
|
Long fkTableId = fkTableColumn.getTableId();
|
|
|
GenTable fkGenTable = remoteGenTableService.getByTableId(fkTableId);
|
|
|
- String fkTableName= fkGenTable.getTableName();
|
|
|
-
|
|
|
- // select * from fkTableName where fkTableColumn.columnName = value;
|
|
|
-
|
|
|
-// jsonObject.put(columnName, "");
|
|
|
-// jsonObject.put("columnName", "");
|
|
|
-
|
|
|
+ // 显示键 table_column 表的id
|
|
|
+ Long dkColumnId = fkGenTable.getDkColumn();
|
|
|
+ GenTableColumn dkTableColumn = remoteGenTableColumnService.getById(dkColumnId);
|
|
|
+ String dkColumnName = dkTableColumn.getColumnName();
|
|
|
+ String fkTableName = fkGenTable.getTableName();
|
|
|
+ Object primaryTableFKvalue = json.get(selfColumnName);
|
|
|
+ // "DEPT_ID": {"value": 104, "name": "开发部"}
|
|
|
+ Map<String, Object> param = Maps.newHashMap();
|
|
|
+ param.put(fkColumnName, primaryTableFKvalue);
|
|
|
+ List<JSONObject> fkList = selectService.selectByMap(fkTableName, param);
|
|
|
+
|
|
|
+ for (JSONObject object : fkList) {
|
|
|
+ Object value = object.get(dkColumnName);
|
|
|
+ jsonObject.put(SINGLE_OBJ_NAME, primaryTableFKvalue);
|
|
|
+ jsonObject.put(SINGLE_OBJ_VALUE, value);
|
|
|
+ json.put(selfColumnName.toLowerCase(), jsonObject);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 功能描述: 把timeStamp转为string
|
|
|
+ * 功能描述: 把timeStamp转为string, 默认类型为:YYYY_MM_DD
|
|
|
*
|
|
|
* @param result 被转的数据
|
|
|
*/
|