|
@@ -5,10 +5,14 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.StringUtils;
|
|
|
import com.boman.common.core.utils.collection.CollectionUtils;
|
|
|
+import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
+import com.boman.common.core.web.domain.AjaxResult;
|
|
|
import com.boman.common.redis.RedisKey;
|
|
|
import com.boman.common.redis.service.RedisService;
|
|
|
import com.boman.gen.domain.GenTable;
|
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
+import com.boman.system.mapper.StandardlyMapper;
|
|
|
+import com.boman.system.service.IBaseSelectService;
|
|
|
import com.boman.system.service.impl.BaseDeleteService;
|
|
|
import com.boman.system.service.impl.BaseSaveService;
|
|
|
import com.boman.system.utils.IdUtils;
|
|
@@ -19,10 +23,12 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
|
|
|
import static com.boman.common.core.utils.obj.ObjectUtils.requiredNonNull;
|
|
|
-import static com.boman.system.common.FormDataConstant.*;
|
|
|
+import static com.boman.system.common.FormDataConstant.CONDITION;
|
|
|
+import static com.boman.system.common.FormDataConstant.SHOW_DATA;
|
|
|
|
|
|
/**
|
|
|
* @author shiqian
|
|
@@ -38,6 +44,8 @@ public class TableServiceCmdService {
|
|
|
private BaseSaveService saveService;
|
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private IBaseSelectService selectService;
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
|
|
|
|
|
@@ -49,7 +57,7 @@ public class TableServiceCmdService {
|
|
|
return baseTableDTO;
|
|
|
}
|
|
|
|
|
|
- public final ValueHolder<RowResult> objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
+ public final AjaxResult objectSave(BaseTableSaveDTO baseTableSaveDTO) {
|
|
|
BaseTableDTO baseTableDTO = packTableDTO(baseTableSaveDTO);
|
|
|
TableServiceContext context = TableServiceContext.createFrom(baseTableDTO);
|
|
|
// BaseSaveService baseSaveService = SpringUtils.getBean(BaseSaveService.class);
|
|
@@ -65,7 +73,7 @@ public class TableServiceCmdService {
|
|
|
LOGGER.error("保存失败,保持的原始数据为: {}", JSON.toJSONString(baseTableSaveDTO));
|
|
|
}
|
|
|
|
|
|
- return ValueHolder.ok(rowResult);
|
|
|
+ return AjaxResult.success(rowResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -74,7 +82,7 @@ public class TableServiceCmdService {
|
|
|
* @param dto 前台传过来的dto
|
|
|
* @return com.boman.system.common.ValueHolder
|
|
|
*/
|
|
|
- public ValueHolder<RowResult> objectDelete(BaseTableSaveDTO dto) {
|
|
|
+ public AjaxResult objectDelete(BaseTableSaveDTO dto) {
|
|
|
requireNonNull(dto.getTable());
|
|
|
Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
|
|
|
requiredNonNull(idArr);
|
|
@@ -85,7 +93,7 @@ public class TableServiceCmdService {
|
|
|
|
|
|
RowResult rowResult = deleteService.objectDelete(idArr, dto.getTable(), requireNonNull(pkName));
|
|
|
LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
- return ValueHolder.ok(rowResult);
|
|
|
+ return AjaxResult.success(rowResult);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -95,7 +103,7 @@ public class TableServiceCmdService {
|
|
|
* @param dto 前台传过来的dto
|
|
|
* @return com.boman.system.common.ValueHolder
|
|
|
*/
|
|
|
- public ValueHolder<RowResult> objectLogicDelete(BaseTableSaveDTO dto) {
|
|
|
+ public AjaxResult objectLogicDelete(BaseTableSaveDTO dto) {
|
|
|
requireNonNull(dto.getTable());
|
|
|
Long[] idArr = CollectionUtils.listToArray(dto.getIdList());
|
|
|
requiredNonNull(idArr);
|
|
@@ -110,31 +118,74 @@ public class TableServiceCmdService {
|
|
|
|
|
|
RowResult rowResult = deleteService.objectLogicDelete(idArr, dto.getTable(), requireNonNull(pkName), jsonObject);
|
|
|
LOGGER.info(rowResult.getMessage() + ", id: {}", Arrays.toString(idArr));
|
|
|
- return ValueHolder.ok(rowResult);
|
|
|
+ return AjaxResult.success(rowResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能描述: 获取单表单数据
|
|
|
*
|
|
|
- * @param condition condition
|
|
|
+ * @param dto condition
|
|
|
* @return com.boman.system.common.ValueHolder
|
|
|
*/
|
|
|
- public ValueHolder<RowResult> getObject(BaseTableSaveDTO dto) {
|
|
|
+ public AjaxResult getObject(BaseTableSaveDTO dto) {
|
|
|
requireNonNull(dto.getTable());
|
|
|
|
|
|
- // 拿到每个字段对应的查询类型,是 = 或者 like 或者 > 或者 <
|
|
|
+ // 拿到每个字段对应的查询类型,=、 like、 >、 <
|
|
|
GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + requireNonNull(dto.getTable()));
|
|
|
requireNonNull(genTable);
|
|
|
JSONObject fixedData = dto.getFixedData();
|
|
|
requireNonNull(fixedData);
|
|
|
// 查询条件
|
|
|
JSONObject condition = fixedData.getJSONObject(CONDITION);
|
|
|
+ List<GenTableColumn> columns = genTable.getColumns();
|
|
|
+ // 封装好以后的查询条件
|
|
|
+ JSONObject packCondition = packColCondition(columns, condition);
|
|
|
// 需要返回到前台的列
|
|
|
JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
|
|
|
+ List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
|
|
|
+ , showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 功能描述: 封装成查询条件 key: 列名, value:查询条件_查询类别
|
|
|
+ * eg: [{"config_name":"系统配置_like"}, {"config_name":"_like"}]
|
|
|
+ *
|
|
|
+ * @param columns columns
|
|
|
+ * @return com.alibaba.fastjson.JSONObject
|
|
|
+ */
|
|
|
+ private JSONObject packColCondition(List<GenTableColumn> columns, JSONObject condition) {
|
|
|
+ requireNonNull(columns);
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject(columns.size());
|
|
|
+ for (Map.Entry<String, Object> entry : condition.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Object value = entry.getValue();
|
|
|
+ for (GenTableColumn column : columns) {
|
|
|
+ // long string collection 暂时只作此三种类型判断
|
|
|
+ if (column.getColumnName().equalsIgnoreCase(key) && ObjectUtils.isNotEmpty(value)) {
|
|
|
+ // columnType 作为判断需不需要转义的一个标准,防止索引失效
|
|
|
+ result.put(key, packValue(String.valueOf(value), column.getQueryType(), column.getColumnType()));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- return ValueHolder.ok("");
|
|
|
+ /**
|
|
|
+ * 功能描述: 封装查询条件,在拼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;
|
|
|
}
|
|
|
}
|