|
|
package com.engine.common.cmd;
|
|
|
|
|
|
import com.engine.common.biz.AbstractCommonCommand;
|
|
|
import com.engine.common.entity.BizLogContext;
|
|
|
import com.engine.common.util.DbTools;
|
|
|
import com.engine.core.interceptor.CommandContext;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import weaver.general.Util;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
public class QueryCommonCmd extends AbstractCommonCommand<Map<String,Object>> {
|
|
|
|
|
|
public QueryCommonCmd(Map<String,Object> params){
|
|
|
this.params=params;
|
|
|
}
|
|
|
@Override
|
|
|
public BizLogContext getLogContext() {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> execute(CommandContext commandContext) {
|
|
|
Map<String,Object> resultMap = new HashMap<>();
|
|
|
String tableName = Util.null2String(params.get("tableName"));
|
|
|
String columns = Util.null2String(params.get("columns"));
|
|
|
String conditions = Util.null2String(params.get("conditions"));
|
|
|
String orderby = Util.null2String(params.get("orderby"));
|
|
|
String limit = Util.null2String(params.get("limit"));
|
|
|
|
|
|
tableName = tableName.replace("join","join");
|
|
|
conditions = conditions.replace("in","in");
|
|
|
String sql = "select "+columns +" from "+tableName;
|
|
|
if (!"".equals(conditions) ){
|
|
|
conditions = conditions.replace(":","=");
|
|
|
if (conditions.indexOf("in")<0){
|
|
|
conditions = conditions.replace(","," and ");
|
|
|
}
|
|
|
sql = sql + " where "+ conditions;
|
|
|
}
|
|
|
if (!"".equals(orderby)){
|
|
|
sql = sql + orderby;
|
|
|
}
|
|
|
if (!"".equals(limit)){
|
|
|
sql = sql + limit;
|
|
|
}
|
|
|
log.info("QueryCommonCmd sql :[{}]",sql);
|
|
|
|
|
|
List<Map<String,Object>> resultList = DbTools.getSqlToList(sql);
|
|
|
|
|
|
resultMap.put("data",resultList);
|
|
|
return resultMap;
|
|
|
}
|
|
|
}
|