|
@@ -3,7 +3,7 @@ package com.boman.system.common;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.boman.common.core.utils.SecurityUtils;
|
|
|
+import com.boman.common.core.utils.DateUtils;
|
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
@@ -12,18 +12,18 @@ import com.boman.common.redis.service.RedisService;
|
|
|
import com.boman.gen.controller.MyController;
|
|
|
import com.boman.gen.domain.GenTable;
|
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
-import com.boman.system.mapper.StandardlyMapper;
|
|
|
+import com.boman.gen.domain.GenTableRelation;
|
|
|
+import com.boman.system.domain.SysDictData;
|
|
|
import com.boman.system.service.*;
|
|
|
import com.boman.system.utils.IdUtils;
|
|
|
+import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.net.URI;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -54,6 +54,8 @@ public class TableServiceCmdService {
|
|
|
private IBaseUpdateService updateService;
|
|
|
@Resource
|
|
|
private RestTemplate restTemplate;
|
|
|
+ @Resource
|
|
|
+ private ISysDictTypeService dictTypeService;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
@@ -121,9 +123,16 @@ public class TableServiceCmdService {
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
- RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"));
|
|
|
- LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
- return AjaxResult.success(rowResult);
|
|
|
+ List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
|
|
|
+ for (Long id : idArr) {
|
|
|
+ RowResult rowResult = deleteService.deleteById(dto.getTable(), pkName, id);
|
|
|
+ result.add(rowResult);
|
|
|
+ LOGGER.info(rowResult.getMessage() + ", id: {}", id);
|
|
|
+ }
|
|
|
+
|
|
|
+ // RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"));
|
|
|
+
|
|
|
+ return AjaxResult.success(result);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -142,12 +151,16 @@ public class TableServiceCmdService {
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, dto.getTable());
|
|
|
String pkName = IdUtils.getPkName(genTable.getColumns());
|
|
|
|
|
|
+ List<RowResult> result = Lists.newArrayListWithCapacity(idArr.length);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put(dto.getLogicDelName(), dto.getLogicDelValue());
|
|
|
+ for (Long id : idArr) {
|
|
|
+ RowResult rowResult = deleteService.objectLogicDelete(new Long[]{id}, dto.getTable(), pkName, jsonObject);
|
|
|
+ result.add(rowResult);
|
|
|
+ LOGGER.info(rowResult.getMessage() + ", id: {}", id);
|
|
|
+ }
|
|
|
|
|
|
- RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName, "主键名称为空"), jsonObject);
|
|
|
- LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
- return AjaxResult.success(rowResult);
|
|
|
+ return AjaxResult.success(result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -181,11 +194,42 @@ public class TableServiceCmdService {
|
|
|
|
|
|
List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
|
|
|
, showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
|
|
|
+ handlerDate(result);
|
|
|
result = isCustomized(dto.getTable(),result,"trigger_retrieve");
|
|
|
rows.put(FormDataConstant.PAGE_ROWS, result);
|
|
|
return AjaxResult.success(rows);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 功能描述: 把timeStamp转为string
|
|
|
+ *
|
|
|
+ * @param result 被转的数据
|
|
|
+ */
|
|
|
+ private void handlerDate(List<JSONObject> result) {
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(result)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (JSONObject jsonObject : result) {
|
|
|
+ getStrByTimeStamp(jsonObject, FormDataConstant.CREATE_TIME);
|
|
|
+ getStrByTimeStamp(jsonObject, FormDataConstant.UPDATE_TIME.toLowerCase());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 把jsonObject中时间类型转为string,再放到jsonObject中,类型为: yyyy-mm-dd
|
|
|
+ *
|
|
|
+ * @param jsonObject jsonObject
|
|
|
+ * @param columnType create_time update_time...
|
|
|
+ */
|
|
|
+ private void getStrByTimeStamp(JSONObject jsonObject, String columnType) {
|
|
|
+ Date date = jsonObject.getTimestamp(columnType);
|
|
|
+ if (null != date) {
|
|
|
+
|
|
|
+ jsonObject.put(columnType, DateUtils.dateTime(date));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 功能描述: 获取单表单数据
|
|
|
*
|
|
@@ -258,13 +302,19 @@ public class TableServiceCmdService {
|
|
|
ArrayList<GenTableColumn> queryList = Lists.newArrayListWithCapacity(16);
|
|
|
for (GenTableColumn column : columns) {
|
|
|
if (GenTableColumn.IS_QUERY.equalsIgnoreCase(column.getIsQuery())) {
|
|
|
+ String dictType = column.getDictType();
|
|
|
+ if (ObjectUtils.isNotEmpty(dictType)) {
|
|
|
+ List<SysDictData> sysDictData1 = dictTypeService.selectDictDataByType(dictType);
|
|
|
+ column.setSysDictData(coverSysDictDataToJSONObject(sysDictData1));
|
|
|
+ }
|
|
|
+
|
|
|
queryList.add(column);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
jsonObject.put(FormDataConstant.QUERY_LIST, queryList);
|
|
|
// genTable.getMenuRole() 暂时数据库没有数据,
|
|
|
- jsonObject.put(FormDataConstant.BUTTON_LIST, genTable.getMenuRole());
|
|
|
+ jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
|
|
|
|
|
|
// 表头
|
|
|
List<GenTableColumn> tableHeadList = columns.stream()
|
|
@@ -274,21 +324,6 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success(jsonObject);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 功能描述: 封装查询条件,在拼sql的时候按照此规则去取值
|
|
|
- * {@link StandardlyMapper.SqlProvider#selectByCondition(java.util.Map)}
|
|
|
- *
|
|
|
- * @param value 查询的值
|
|
|
- * @param queryType queryType
|
|
|
- * @param columnType columnType
|
|
|
- * @return java.lang.String
|
|
|
- */
|
|
|
- public String packValue(String value, String queryType, String columnType) {
|
|
|
- requireNonNull(value);
|
|
|
- requireNonNull(queryType);
|
|
|
- return value + "_" + queryType + "_" + columnType;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 功能描述: 获取表单子表
|
|
|
*
|
|
@@ -301,9 +336,13 @@ public class TableServiceCmdService {
|
|
|
List<GenTable> childTableList = genTable.getRelationList();
|
|
|
// 此表没有关联子表,查啥查
|
|
|
requireNonNull(childTableList);
|
|
|
-
|
|
|
+ // todo
|
|
|
for (GenTable childTable : childTableList) {
|
|
|
String childTableName = childTable.getTableName();
|
|
|
+ Long childTableTableId = childTable.getTableId();
|
|
|
+ List<GenTableColumn> childColumns = childTable.getColumns();
|
|
|
+ // column_name = 先根据tableName查到id,再用id到relation中查到relation_child_id, 在用这个值去到tableColumn中查到column_name
|
|
|
+ // select * from childTableName where column_name = objId
|
|
|
|
|
|
|
|
|
}
|
|
@@ -312,6 +351,27 @@ public class TableServiceCmdService {
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ public String getChildColumnNameByParentTableName(GenTable parentGenTable, Long childTableTableId){
|
|
|
+ requireNonNull(parentGenTable.getTableName(), "主表名称为空");
|
|
|
+// GenTable primaryTable = redisService.getCacheObject(RedisKey.TABLE_INFO + genTable.getTableName());
|
|
|
+ Long parentTableId = parentGenTable.getTableId();
|
|
|
+ List<GenTableRelation> relations = redisService.getCacheObject(RedisKey.RELATION_INFO);
|
|
|
+ relations = relations.stream()
|
|
|
+ .filter(relation -> relation.getRelationParentId().equals(parentTableId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (GenTableRelation relation : relations) {
|
|
|
+ if (relation.getRelationChildId().equals(6L)) {
|
|
|
+ // tableColumnService.selectGenTableColumnListByTableId(childTableTableId);
|
|
|
+// return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return "";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 功能描述: 表单提交接口
|
|
|
*
|
|
@@ -429,7 +489,7 @@ public class TableServiceCmdService {
|
|
|
// todo redis中未找到,要去查数据库,然后再塞进去
|
|
|
private GenTable getTableFromRedisByTableName(String redisKeyPrefix, String tableName) {
|
|
|
GenTable genTable = redisService.getCacheObject(redisKeyPrefix + requireNonNull(tableName));
|
|
|
- return requireNonNull(genTable);
|
|
|
+ return requireNonNull(genTable, "未找到表对应的信息");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -445,7 +505,31 @@ public class TableServiceCmdService {
|
|
|
public AjaxResult getByTableName(BaseTableSaveDTO condition) {
|
|
|
// requiredNonNull(condition.getTable(), "表名为空");
|
|
|
GenTable genTable = getTableFromRedisByTableName(RedisKey.TABLE_INFO, condition.getTable());
|
|
|
+ List<GenTableColumn> columns = genTable.getColumns();
|
|
|
+ for (GenTableColumn column : columns) {
|
|
|
+ String dictType = column.getDictType();
|
|
|
+ if (ObjectUtils.isNotEmpty(dictType)) {
|
|
|
+ List<SysDictData> sysDictData1 = dictTypeService.selectDictDataByType(dictType);
|
|
|
+ column.setSysDictData(coverSysDictDataToJSONObject(sysDictData1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return AjaxResult.success(genTable);
|
|
|
}
|
|
|
+
|
|
|
+ public List<JSONObject> coverSysDictDataToJSONObject(List<SysDictData> sysDictData) {
|
|
|
+ List<JSONObject> result = Lists.newArrayListWithCapacity(sysDictData.size());
|
|
|
+ for (SysDictData data : sysDictData) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ String dictLabel = data.getDictLabel();
|
|
|
+ String dictValue = data.getDictValue();
|
|
|
+ jsonObject.put(DictConstant.DICT_LABEL, dictLabel);
|
|
|
+ jsonObject.put(DictConstant.DICT_VALUE, dictValue);
|
|
|
+ result.add(jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|