|
@@ -7,26 +7,26 @@ package com.keao.edu.common.service.impl;
|
|
|
* @author pengdc
|
|
|
* @create 2015年7月13日
|
|
|
*/
|
|
|
+
|
|
|
import com.keao.edu.common.dal.BaseDAO;
|
|
|
import com.keao.edu.common.page.PageInfo;
|
|
|
import com.keao.edu.common.page.QueryInfo;
|
|
|
import com.keao.edu.common.service.BaseService;
|
|
|
import com.keao.edu.util.collection.MapUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.ibatis.io.Resources;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
-import java.lang.reflect.ParameterizedType;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* SERVICE操作基类
|
|
@@ -164,6 +164,67 @@ public abstract class BaseServiceImpl<PK extends Serializable, T> implements Bas
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public <K extends List, Y, Z> Map<Y,Z> getMap(String tableName, String columnKey, String columnValue, Map<String,Object> paramMap, Class<Y> keyType, Class<Z> valueType){
|
|
|
+ StringBuffer sql=new StringBuffer();
|
|
|
+ Map<Y,Z> result = new HashMap();
|
|
|
+ try {
|
|
|
+ Connection connection = sqlSessionFactory.openSession().getConnection();
|
|
|
+ sql.append("SELECT ").append(columnKey).append(",").append(columnValue).append(" FROM ").append(tableName).append(" WHERE ");
|
|
|
+ boolean resultFlag = false;
|
|
|
+ for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
|
|
|
+ if(entry.getValue() instanceof List){
|
|
|
+ List entryValue = (List) entry.getValue();
|
|
|
+ if(!CollectionUtils.isEmpty(entryValue)){
|
|
|
+ sql.append(entry.getKey()).append(" IN (").append(StringUtils.join(entryValue, ",")).append(") AND ");
|
|
|
+ resultFlag = true;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sql.append(entry.getKey()).append(" = ").append(entry.getValue()).append(" AND ");
|
|
|
+ resultFlag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!resultFlag){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ sql.append(" 1 = 1 GROUP BY ").append(columnKey);
|
|
|
+ PreparedStatement ps = connection.prepareStatement(sql.toString());
|
|
|
+ ResultSet resultSet = ps.executeQuery();
|
|
|
+ while (resultSet.next()){
|
|
|
+ Y key;
|
|
|
+ Z value;
|
|
|
+ if(keyType.isAssignableFrom(BigDecimal.class)){
|
|
|
+ key = (Y) BigDecimal.class.getDeclaredConstructor(String.class).newInstance(resultSet.getString(1));
|
|
|
+ }else if(keyType.isAssignableFrom(String.class)){
|
|
|
+ key = (Y) resultSet.getString(1);
|
|
|
+ }else{
|
|
|
+ key = (Y) keyType.getMethod("valueOf", String.class).invoke(null,resultSet.getString(1));
|
|
|
+ }
|
|
|
+ if(valueType.isAssignableFrom(BigDecimal.class)){
|
|
|
+ value = (Z) BigDecimal.class.getDeclaredConstructor(String.class).newInstance(resultSet.getString(2));
|
|
|
+ }else if(valueType.isAssignableFrom(String.class)){
|
|
|
+ value = (Z) resultSet.getString(2);
|
|
|
+ }else{
|
|
|
+ value = (Z) valueType.getMethod("valueOf", String.class).invoke(null,resultSet.getString(2));
|
|
|
+ }
|
|
|
+ result.put(key, value);
|
|
|
+ }
|
|
|
+ if(resultSet!=null){
|
|
|
+ resultSet.close();
|
|
|
+ }
|
|
|
+ if(ps!=null){
|
|
|
+ ps.close();
|
|
|
+ }
|
|
|
+ if(connection!=null){
|
|
|
+ connection.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public <K extends List> Map<String, String> getMap(String tableName, String columnKey, String columnValue, K ids) {
|
|
|
StringBuffer sql=new StringBuffer();
|
|
|
Map<String, String> result=new HashMap();
|