e47d315abe1265d45cd1c22eabda526c6b45ab98.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. package com.sinosoft.em.baobiao.xianlutingyun.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.Date;
  7. import java.util.List;
  8. import java.util.Map;
  9. import net.sf.json.JSONArray;
  10. import org.apache.log4j.Logger;
  11. import com.formaction.Parameter;
  12. import com.formaction.vo.Msg;
  13. import com.persistence.DbConnection;
  14. import com.persistence.service.PersistenceFactory;
  15. import com.persistence.service.assitant.generator.IdentityGenerator;
  16. import com.persistence.service.exception.PersistenceException;
  17. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  18. import com.sinosoft.common.excel.JsonPluginsUtil;
  19. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  20. public class DetailDao {
  21. private Logger log = Logger.getLogger(this.getClass());
  22. /**
  23. * 根据grid表格的列名和表格类型获得表头名称
  24. * @param name
  25. * @param type
  26. * @return
  27. * @throws ClassNotFoundException
  28. */
  29. public String getTableHead(String name,String type) throws ClassNotFoundException{
  30. String sql = "select distinct table_head from emc_am_report_dictionary where table_column = ? and report_type=?";
  31. Connection conn = null;
  32. PreparedStatement ps = null;
  33. ResultSet rs = null;
  34. DbConnection db = new DbConnection();
  35. //StringBuffer sb = new StringBuffer();
  36. //List<String> list = new ArrayList<String>();
  37. String tableHead ="";
  38. try {
  39. conn = db.getConnection();
  40. ps = conn.prepareStatement(sql);
  41. ps.setString(1, name);
  42. ps.setString(2, type);
  43. rs = ps.executeQuery();
  44. while(rs.next()){
  45. /*sb.append("{");
  46. sb.append("\"TABLE_HEAD\":\""+rs.getString("table_head")+"\"");
  47. sb.append("},");*/
  48. tableHead = rs.getString("table_head");
  49. }
  50. /* if(sb.lastIndexOf(",")>-1){
  51. sb.deleteCharAt(sb.lastIndexOf(","));
  52. }
  53. list.add(sb.toString());
  54. */
  55. } catch (SQLException e) {
  56. log.info(e.getMessage(),e);
  57. }finally{
  58. db.close(rs);
  59. db.close(ps);
  60. db.close(conn);
  61. }
  62. return tableHead;
  63. }
  64. /**
  65. * 返回表头和表格所需填充的数据
  66. * @param name
  67. * @param type
  68. * @param level
  69. * @param fd_id
  70. * @param page
  71. * @param pageSize
  72. * @return
  73. * @throws ClassNotFoundException
  74. */
  75. public String getInfo(String type,String level,String fd_id ,int page,int pageSize,String deatil) throws ClassNotFoundException{
  76. String result = "";
  77. String sqls = getSql(type,level,fd_id,page,pageSize);
  78. String sql1 ="";
  79. if("1".equals(deatil)){
  80. sql1 = sqls.split("[|]")[1];
  81. }else{
  82. sql1 = sqls.split("[|]")[0];
  83. }
  84. log.info(sql1+"==============sql1");
  85. List<Map<String,String>> list = null;
  86. try {
  87. if(!"".equals(sql1)){
  88. list = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(
  89. 99, sql1);
  90. /*list1 = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(
  91. 99, sql1);*/
  92. result = JSONArray.fromObject(list).toString();
  93. result = "{\"rows\":" + result + "}";
  94. //tableHead = getTableHead(level,type);
  95. //vo = new DetailVo();
  96. // vo.setTableHead(tableHead);
  97. // vo.setResult(result);
  98. //li = new ArrayList<DetailVo>();
  99. //li.add(vo);
  100. }
  101. } catch (PersistenceException e) {
  102. log.error(e.getMessage(),e);
  103. }
  104. if(!"".equals(result)&&result!=null){
  105. return result;
  106. }else{
  107. return null;
  108. }
  109. }
  110. public String getSql(String type,String level,String fd_id,int page,int pageSize){
  111. String sql = "";
  112. String sql1 = "";
  113. if("1".equals(type)){
  114. sql = "select top "+(page-1)*pageSize+","+pageSize +" fd_objectid,report_id,route_name,route_level,comp_id,"
  115. + "comp_name,end_time,gz_type,start_time,loss_load,count,ofline_stat_qk from route_ofline_detail where report_id='"+fd_id+"' and types = '"+level+"'";
  116. sql1 = "select fd_objectid,report_id,route_name,route_level,comp_id,"
  117. + "comp_name,end_time,gz_type,start_time,loss_load,count,ofline_stat_qk from route_ofline_detail where report_id='"+fd_id+"' and types = '"+level+"'";
  118. }/*else if("2".equals(type)){
  119. sql = "select top "+(page-1)*pageSize+","+pageSize+" fd_objectid,report_id,station_name,route_level,comp_name,stop_time,fail_count,start_time,comp_id from bdz_xq_detail where report_id='"+fd_id+"' and types ='"+level+"'";
  120. sql1 = "select fd_objectid,report_id,station_name,route_level,comp_name,stop_time,fail_count,start_time,comp_id from bdz_xq_detail where report_id='"+fd_id+"' and types ='"+level+"'";
  121. }*/else if("3".equals(type)){
  122. sql = "select top "+(page-1)*pageSize+","+pageSize+" fd_objectid,report_id ,comp_id ,sb_name,fail_type,end_time,start_time,fail_count,comp_name from xldg_xq_detail where report_id ='"+fd_id+"' and types ='"+level+"'";
  123. sql1 ="select fd_objectid,report_id ,comp_id ,sb_name,fail_type,end_time,start_time,fail_count,comp_name from xldg_xq_detail where report_id ='"+fd_id+"' and types ='"+level+"'";
  124. }else if("5".equals(type)){
  125. sql = "select top "+(page-1)*pageSize+","+pageSize+" fd_objectid,report_id,comp_id,client_number,client_name,client_level,support_station,stop_time,is_had,route_level from tdqk_xq_detail where report_id ='"+fd_id+"' and types ='"+level+"'";
  126. sql1 = "select fd_objectid,report_id,comp_id,client_number,client_name,client_level,support_station,stop_time,is_had,route_level from tdqk_xq_detail where report_id ='"+fd_id+"' and types ='"+level+"'";
  127. }else if("8".equals(type)){
  128. sql = "select top "+(page-1)*pageSize+","+pageSize+" fd_objectid,report_id,comp_id,comp_name,sd_power_cable,sd_circuit,bd_first,bd_second,pd_circuit,pd_power_cable,dy_station,yj_bd,communication,inter_info,test,total from yjzy_xq_detail where report_id ='"+fd_id+"' and types='"+level+"'";
  129. sql1 = "select fd_objectid,report_id,comp_id,comp_name,sd_power_cable,sd_circuit,bd_first,bd_second,pd_circuit,pd_power_cable,dy_station,yj_bd,communication,inter_info,test,total from yjzy_xq_detail where report_id ='"+fd_id+"' and types='"+level+"'";
  130. }else if("4".equals(type)){
  131. sql = "select top "+(page-1)*pageSize+","+pageSize+" fd_objectid,report_id,comp_id,name,voltage,transformer_name,device_type,damage_type,length,count,is_repair from shousun_detail where report_id = '"+fd_id+"' and types = '"+level+"'";
  132. sql1 = "select fd_objectid,report_id,comp_id,name,voltage,transformer_name,device_type,damage_type,length,count,is_repair from shousun_detail where report_id = '"+fd_id+"' and types = '"+level+"'";
  133. }else if("101".equals(type)){
  134. sql = "select top "+(page-1)*pageSize+","+pageSize+" bdzmc,dydj,sfyhf,tysj,hfsj from SUBSTATION_STOPPAGE_RECOVERY where report_id = '"+fd_id+"' and dydj = (select distinct table_head from emc_am_report_dictionary where report_type = '"+type+"' and table_column = '"+level+"')";
  135. sql1 = "select bdzmc,dydj,sfyhf,tysj,hfsj from SUBSTATION_STOPPAGE_RECOVERY where report_id = '"+fd_id+"' and dydj = (select distinct table_head from emc_am_report_dictionary where report_type = '"+type+"' and table_column = '"+level+"')";
  136. }
  137. return sql+"|"+sql1;
  138. }
  139. public Msg operateDetail(String json,String report_id, String route_level, String comp_id,String type) throws ClassNotFoundException{
  140. BaoBiaoDao dao = new BaoBiaoDao();
  141. String date = dao.formatTime(new Date());
  142. Connection conn = null;
  143. PreparedStatement ps = null;
  144. PreparedStatement ps1 = null;
  145. DbConnection db = new DbConnection();
  146. String sqls = getOperateSql(type);
  147. String sql = sqls.split("[|]")[0];
  148. String sql1 = sqls.split("[|]")[1];
  149. List<Map<String, String>> list = JsonPluginsUtil.jsonToMapList(json);
  150. Msg m = null;
  151. try {
  152. if(!"".equals(sql)&&!"".equals(sql1)){
  153. conn = db.getConnection();
  154. conn.setAutoCommit(false);
  155. ps1 = conn.prepareStatement(sql1);
  156. log.info(report_id+"=========report_id");
  157. log.info(route_level+"=========route_level");
  158. ps1.setString(1, report_id);
  159. ps1.setString(2, route_level);
  160. ps1.executeUpdate();
  161. int num = 0;
  162. m = new Msg();
  163. ps = conn.prepareStatement(sql);
  164. log.info(list.size()+"==================");
  165. for(int i=0;i<list.size();i++){
  166. Map<String, String> map = list.get(i);
  167. if("1".equals(type)){
  168. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  169. ps.setString(2, report_id);
  170. ps.setString(3, map.get("ROUTE_NAME"));
  171. ps.setString(4, map.get("ROUTE_LEVEL"));
  172. ps.setString(5, comp_id);
  173. /* ps.setString(6, map.get("OFLINE_STAT"));*/
  174. ps.setString(6, date);
  175. ps.setString(7, "0");
  176. ps.setString(8, map.get("COMP_NAME"));
  177. ps.setString(9, map.get("END_TIME"));
  178. ps.setString(10, map.get("GZ_TYPE"));
  179. ps.setString(11, map.get("START_TIME"));
  180. ps.setString(12, map.get("LOSS_LOAD"));
  181. ps.setString(13, map.get("COUNT"));
  182. ps.setString(14, map.get("OFLINE_STAT_QK"));
  183. ps.setString(15, route_level);
  184. ps.executeUpdate();
  185. }/*else if("2".equals(type)){
  186. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  187. ps.setString(2, report_id);
  188. ps.setString(3, map.get("STATION_NAME"));
  189. ps.setString(4, map.get("ROUTE_LEVEL"));
  190. ps.setString(5, map.get("COMP_NAME"));
  191. ps.setString(6, map.get("STOP_TIME"));
  192. ps.setString(7, map.get("FAIL_COUNT"));
  193. ps.setString(8, map.get("START_TIME"));
  194. ps.setString(9, "0");
  195. ps.setString(10, date);
  196. ps.setString(11, comp_id);
  197. ps.setString(12, route_level);
  198. ps.executeUpdate();
  199. }*/else if("3".equals(type)){
  200. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  201. ps.setString(2, report_id);
  202. ps.setString(3, route_level);
  203. ps.setString(4, comp_id);
  204. ps.setString(5, map.get("SB_NAME"));
  205. ps.setString(6, map.get("FAIL_TYPE"));
  206. ps.setString(7, map.get("END_TIME"));
  207. ps.setString(8, map.get("START_TIME"));
  208. ps.setString(9, map.get("FAIL_COUNT"));
  209. ps.setString(10, "0");
  210. ps.setString(11, date);
  211. ps.setString(12, map.get("COMP_NAME"));
  212. ps.executeUpdate();
  213. }else if("5".equals(type)){
  214. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  215. ps.setString(2, report_id);
  216. ps.setString(3, comp_id);
  217. ps.setString(4, route_level);
  218. ps.setString(5, map.get("CLIENT_NUMBER"));
  219. ps.setString(6, map.get("CLIENT_NAME"));
  220. ps.setString(7, map.get("CLIENT_LEVEL"));
  221. ps.setString(8, map.get("SUPPORT_STATION"));
  222. ps.setString(9, map.get("STOP_TIME"));
  223. ps.setString(10,map.get("IS_HAD"));
  224. ps.setString(11,map.get("0"));
  225. ps.setString(12,date);
  226. ps.setString(13, map.get("ROUTE_LEVEL"));
  227. ps.executeUpdate();
  228. }else if("8".equals(type)){
  229. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  230. ps.setString(2, report_id);
  231. ps.setString(3, comp_id);
  232. ps.setString(4, route_level);
  233. // ps.setString(5, map.get("COMP_NAME")==""?"0":);
  234. log.info(map.get("SD_CIRCUIT").equals("")+"======null");
  235. ps.setString(5, "".equals(map.get("SD_POWER_CABLE"))?"0":map.get("SD_POWER_CABLE"));
  236. ps.setString(6, "".equals(map.get("SD_CIRCUIT"))?"0":map.get("SD_CIRCUIT"));
  237. ps.setString(7, "".equals(map.get("BD_FIRST"))?"0":map.get("BD_FIRST"));
  238. ps.setString(8, "".equals(map.get("BD_SECOND"))?"0":map.get("BD_SECOND"));
  239. ps.setString(9,"".equals(map.get("PD_CIRCUIT"))?"0":map.get("PD_CIRCUIT"));
  240. ps.setString(10,"".equals(map.get("PD_POWER_CABLE"))?"0":map.get("PD_POWER_CABLE"));
  241. ps.setString(11,"".equals(map.get("DY_STATION"))?"0":map.get("DY_STATION"));
  242. ps.setString(12,"".equals(map.get("YJ_BD")) ?"0":map.get("YJ_BD"));
  243. ps.setString(13, "".equals(map.get("COMMUNICATION"))?"0":map.get("COMMUNICATION"));
  244. ps.setString(14, "".equals(map.get("INTER_INFO"))?"0":map.get("INTER_INFO"));
  245. ps.setString(15, "".equals(map.get("TEST"))?"0":map.get("TEST"));
  246. ps.setString(16,map.get("TOTAL"));
  247. ps.setString(17, "0");
  248. ps.setString(18, date);
  249. ps.executeUpdate();
  250. }else if("4".equals(type)){
  251. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  252. ps.setString(2, report_id);
  253. ps.setString(3, comp_id);
  254. ps.setString(4, route_level);
  255. ps.setString(5, date);
  256. ps.setString(6, "0");
  257. ps.setString(7, map.get("NAME"));
  258. ps.setString(8, map.get("VOLTAGE"));
  259. ps.setString(9, map.get("TRANSFORMER_NAME"));
  260. ps.setString(10,map.get("DEVICE_TYPE"));
  261. ps.setString(11,map.get("DAMAGE_TYPE"));
  262. ps.setString(12,map.get("LENGTH"));
  263. ps.setString(13,map.get("COUNT"));
  264. ps.setString(14, map.get("IS_REPAIR"));
  265. ps.executeUpdate();
  266. }
  267. num++;
  268. }
  269. if(num==list.size()){
  270. conn.commit();
  271. m.setSucsess(new Boolean(true).toString());
  272. m.setInfo(Parameter.CREATE_SUCSESS);
  273. }else{
  274. conn.rollback();
  275. m.setSucsess(new Boolean(false).toString());
  276. m.setInfo(Parameter.CREATE_FAILURE);
  277. }
  278. }
  279. } catch (SQLException e) {
  280. log.error(e.getMessage(),e);
  281. }finally{
  282. db.close(ps1);
  283. db.close(ps);
  284. db.close(conn);
  285. }
  286. if(m!=null){
  287. return m;
  288. }else{
  289. return null;
  290. }
  291. }
  292. public String getOperateSql(String type){
  293. String sql = "";
  294. String sql1 = "";
  295. if("1".equals(type)){
  296. sql = "insert into route_ofline_detail(fd_objectid,report_id,route_name,route_level,comp_id,updatedate,is_del,"
  297. + "comp_name,end_time,gz_type,start_time,loss_load,count,ofline_stat_qk,types) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  298. sql1 = "delete from route_ofline_detail where report_id = ? and types = ?";
  299. }/*else if("2".equals(type)){
  300. sql = "insert into bdz_xq_detail(fd_objectid,report_id,station_name,route_level,comp_name,stop_time,fail_count,start_time,is_del,updatedate,comp_id,types) values(?,?,?,?,?,?,?,?,?,?,?,?)";
  301. sql1 = "delete from bdz_xq_detail where report_id = ? and types = ?";
  302. }*/else if("3".equals(type)){
  303. sql = "insert into xldg_xq_detail(fd_objectid,report_id,types,comp_id,sb_name,fail_type,end_time,start_time,fail_count,is_del,updatedate,comp_name) values(?,?,?,?,?,?,?,?,?,?,?,?) ";
  304. sql1 = "delete from xldg_xq_detail where report_id = ? and types = ?";
  305. }else if("5".equals(type)){
  306. sql = "insert into tdqk_xq_detail(fd_objectid,report_id,comp_id,types,client_number,client_name,client_level,support_station,stop_time,is_had,is_del,updatedate,route_level) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
  307. sql1 = "delete from tdqk_xq_detail where report_id = ? and types = ?";
  308. }else if("8".equals(type)){
  309. sql = "insert into yjzy_xq_detail(fd_objectid,report_id,comp_id,types,sd_power_cable,sd_circuit,bd_first,bd_second,pd_circuit,pd_power_cable,dy_station,yj_bd,communication,inter_info,test,total,is_del,updatedate)"
  310. + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  311. sql1 = "delete from yjzy_xq_detail where report_id = ? and types = ? ";
  312. }else if("4".equals(type)){
  313. sql ="insert into shousun_detail(fd_objectid,report_id,comp_id,types,updatedate,is_del,name,voltage,transformer_name,device_type,damage_type,length,count,is_repair) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  314. sql1 ="delete from shousun_detail where report_id = ? and types = ?";
  315. }
  316. return sql+"|"+sql1;
  317. }
  318. public String getClassIdByType(String report_type){
  319. String sql = "select classid from detail_dictionary where report_type = ?";
  320. String result = "";
  321. try {
  322. List<String[]> list= new ORGTemplate().getSearchResult(sql, report_type);
  323. result = list.get(0)[0];
  324. } catch (SQLException e) {
  325. log.info(e.getMessage(),e);
  326. }
  327. return result;
  328. }
  329. }