4f40ee3ff79705ff33012f6c231185ed05c89c2a.svn-base 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package com.sinosoft.cm.chart.dao;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import org.apache.commons.logging.Log;
  6. import org.apache.commons.logging.LogFactory;
  7. import com.sinosoft.cm.CMTemplate;
  8. import com.sinosoft.cm.common.StringUtils;
  9. import com.sinosoft.cm.ex.SQLStringException;
  10. public class ChartDaoImpl implements IChartDao {
  11. private Log log = LogFactory.getLog(ChartDaoImpl.class);
  12. protected CMTemplate cmt=null;
  13. protected Map<String,String> map;
  14. public ChartDaoImpl(){
  15. cmt=new CMTemplate();
  16. map=new HashMap<String,String>();
  17. }
  18. /**
  19. * 通过sql语句名查询
  20. * @param sqlName sql语句名
  21. * @param list 替换列表
  22. * @param args 参数
  23. * @return
  24. * @throws SQLStringException
  25. */
  26. public List<Map<String,String>> findAllByNameAndIN(String sqlName,List<String> list,Object...args) throws SQLStringException {
  27. List<Map<String,String>> listMap=null;
  28. String strSql=map.get(sqlName);
  29. if(strSql.toLowerCase()==null || "".equals(strSql))
  30. throw new SQLStringException("sql语句不存在;sqlName="+sqlName);
  31. if(list!=null)
  32. try {
  33. strSql=StringUtils.replace(strSql,"_\\?_",list);
  34. } catch (Exception e) {
  35. log.error(e.getMessage());;
  36. }
  37. log.info("sql======"+strSql);
  38. listMap=cmt.queryMoreTypeToMap(strSql, args);
  39. return listMap;
  40. }
  41. /**
  42. * 重载findAllByNameAndIN方法
  43. * @param sqlName sql语句名
  44. * @param str 替换的字符串
  45. * @param sprateStr str的切割字符串
  46. * @param args 可变参数
  47. * @return
  48. * @throws SQLStringException
  49. */
  50. public List<Map<String,String>> findAllByNameAndIN(String sqlName,String str,String sprateStr,Object...args) throws SQLStringException{
  51. List<Map<String,String>> listMap=null;
  52. if(str==null || str.toLowerCase().equals("null") ||"".equals(str.trim()))
  53. throw new SQLStringException("替换字段异常=="+str);
  54. String sqlStr=map.get(sqlName);
  55. if(sprateStr==null ||"".equals(sprateStr.trim())){
  56. sqlStr=sqlStr.replace("_?_", str);
  57. }else{
  58. String[] arr=str.split(sprateStr);
  59. try {
  60. sqlStr=StringUtils.replace(sqlStr, "_\\?_", arr);
  61. arr=null;
  62. } catch (Exception e) {
  63. log.error(e.getMessage());
  64. }
  65. }
  66. log.info("sql:"+sqlName+"======"+sqlStr);
  67. listMap=cmt.queryMoreTypeToMap(sqlStr, args);
  68. sqlStr=null;
  69. return listMap;
  70. }
  71. /**
  72. * 重载findAllByNameAndIN方法 查询最新一条已发布事件
  73. * 2016/11/13 谢仲铠修改
  74. * @param sqlName sql语句名
  75. * @param year 年份
  76. * @param compId id
  77. * @return
  78. * @throws SQLStringException
  79. *
  80. */
  81. public List<Map<String,String>> findAllByNameAndIN(String sqlName,Object...args) throws SQLStringException{
  82. List<Map<String,String>> listMap=null;
  83. /*if(str==null || str.toLowerCase().equals("null") ||"".equals(str.trim()))
  84. throw new SQLStringException("替换字段异常=="+str);*/
  85. String sqlStr=map.get(sqlName);
  86. /*if(sprateStr==null ||"".equals(sprateStr.trim())){
  87. sqlStr=sqlStr.replace("_?_", str);
  88. }else{
  89. String[] arr=str.split(sprateStr);
  90. try {
  91. sqlStr=StringUtils.replace(sqlStr, "_\\?_", arr);
  92. arr=null;
  93. } catch (Exception e) {
  94. log.error(e.getMessage());
  95. }
  96. }*/
  97. log.info("sql:"+sqlName+"======"+sqlStr);
  98. listMap=cmt.queryMoreTypeToMap(sqlStr, args);
  99. sqlStr=null;
  100. return listMap;
  101. }
  102. /**
  103. * findAllByNameAndINNumber方法 通过事件查询最新一条已发布的通知单
  104. * 2016/11/13 谢仲铠修改
  105. * @param sqlName sql语句名
  106. * @param year 年份
  107. * @param compId id
  108. * @return
  109. * @throws SQLStringException
  110. *
  111. */
  112. public List<Map<String,String>> findAllByNameAndINNumber(String sqlName,Object...args) throws SQLStringException{
  113. List<Map<String,String>> listMap=null;
  114. String sqlStr=map.get(sqlName);
  115. log.info("sql:"+sqlName+"======"+sqlStr);
  116. listMap=cmt.queryMoreTypeToMap(sqlStr, args);
  117. sqlStr=null;
  118. return listMap;
  119. }
  120. /**
  121. * 重载findAllByNameAndIN方法
  122. * @param sqlName sql语句名
  123. * @param str 替换的字符串
  124. * @param sprateStr str的切割字符串
  125. * @param str1 替换的字符串
  126. * @param sprateStr1 str1的切割字符串
  127. * @param args 可变参数
  128. * @return
  129. * @throws SQLStringException
  130. */
  131. public List<Map<String,String>> findAllByNameAndIN1(String sqlName,String str,String sprateStr,String str1,String sprateStr1,Object...args) throws SQLStringException{
  132. List<Map<String,String>> listMap=null;
  133. if(str==null || str.toLowerCase().equals("null") ||"".equals(str.trim()))
  134. throw new SQLStringException("替换字段异常=="+str);
  135. String sqlStr=map.get(sqlName);
  136. if(sprateStr==null ||"".equals(sprateStr.trim())){
  137. sqlStr=sqlStr.replace("_?_", str);
  138. }else{
  139. String[] arr=str.split(sprateStr);
  140. try {
  141. sqlStr=StringUtils.replace(sqlStr, "_\\?_", arr);
  142. arr=null;
  143. } catch (Exception e) {
  144. log.error(e.getMessage());
  145. }
  146. }
  147. log.info("sql======"+sqlStr);
  148. if(str1==null || str1.toLowerCase().equals("null") ||"".equals(str1.trim()))
  149. throw new SQLStringException("替换字段异常=="+str1);
  150. if(sprateStr1==null ||"".equals(sprateStr1.trim())){
  151. sqlStr=sqlStr.replace("%?%", str);
  152. }else{
  153. String[] arr=str1.split(sprateStr1);
  154. try {
  155. sqlStr=StringUtils.replace(sqlStr, "%\\?%", arr);
  156. arr=null;
  157. } catch (Exception e) {
  158. log.error(e.getMessage());
  159. }
  160. }
  161. log.info("sql======"+sqlStr);
  162. listMap=cmt.queryMoreTypeToMap(sqlStr, args);
  163. sqlStr=null;
  164. return listMap;
  165. }
  166. }