ecology_maven/com/api/aiyh_pcn/patentWall/dao/PatentWallMapping.java

88 lines
2.5 KiB
Java
Raw Normal View History

2021-11-25 21:46:05 +08:00
package com.api.aiyh_pcn.patentWall.dao;
import aiyh.utils.Util;
import aiyh.utils.zwl.common.ToolUtil;
import com.api.aiyh_pcn.patentWall.dto.FilterWhere;
2021-11-25 21:46:05 +08:00
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import weaver.conn.RecordSet;
2021-11-25 21:46:05 +08:00
import java.util.ArrayList;
2021-11-25 21:46:05 +08:00
import java.util.List;
import java.util.Map;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:28
*/
public class PatentWallMapping {
private final ToolUtil toolUtil = new ToolUtil();
public List<Map<String, Object>> getAllList(String tableName){
RecordSet rs = new RecordSet();
String query = "select * from " + tableName;
rs.executeQuery(query);
return Util.recordSet2MapList(rs);
}
public List<Map<String,Object>> getListByFilterWhere(List<FilterWhere> filterWheres, String tableName) {
StringBuilder whereBuilder = new StringBuilder(" where ");
List<String> args = new ArrayList<>();
for (FilterWhere filterWhere : filterWheres) {
whereBuilder.append(" add ");
if(filterWhere.getType() == 1){
// 等于
whereBuilder.append(filterWhere.getDbField())
.append(" = ? ");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 2){
// 大于
whereBuilder.append(filterWhere.getDbField())
.append(" > ?");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 3){
// 小于
whereBuilder.append(filterWhere.getDbField())
.append(" < ?");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 4){
// in
whereBuilder.append(filterWhere.getDbField())
.append(" in ( ")
.append(filterWhere.getValue())
.append(") ");
continue;
}
if(filterWhere.getType() == 5){
// 日期大于
whereBuilder.append(" DATE_FORMAT(")
.append(filterWhere.getDbField())
.append(",'%y-%m-%d') > ")
.append("DATE_FORMAT(?,'%y-%m-%d')");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 6){
// 日期小于
whereBuilder.append(" DATE_FORMAT(")
.append(filterWhere.getDbField())
.append(",'%y-%m-%d') < ")
.append("DATE_FORMAT(?,'%y-%m-%d')");
args.add(filterWhere.getValue());
continue;
}
}
RecordSet rs = new RecordSet();
String query = "select * from " + tableName + whereBuilder.toString().replace(" where add "," where ");
rs.executeQuery(query,args);
toolUtil.writeDebuggerLog(String.format("执行SQL {%s} ---> 参数: {%s}",query,args));
return Util.recordSet2MapList(rs);
2021-11-25 21:46:05 +08:00
}
}