915ddf5f50ca7f2f688a046d4ecdf7857c08ea8f.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. /**
  140. * 详情保存
  141. * @param json
  142. * @param report_id 实体数据行的fd_objectid
  143. * @param route_level
  144. * @param comp_id
  145. * @param type 报表类型
  146. * @return
  147. * @throws ClassNotFoundException
  148. */
  149. public Msg operateDetail(String json,String report_id, String route_level, String comp_id,String type) throws ClassNotFoundException{
  150. BaoBiaoDao dao = new BaoBiaoDao();
  151. String date = dao.formatTime(new Date());
  152. Connection conn = null;
  153. PreparedStatement ps = null;
  154. PreparedStatement ps1 = null;
  155. DbConnection db = new DbConnection();
  156. String sqls = getOperateSql(type);
  157. String sql = sqls.split("[|]")[0];//插入数据
  158. String sql1 = sqls.split("[|]")[1];//删除数据
  159. List<Map<String, String>> list = JsonPluginsUtil.jsonToMapList(json);
  160. Msg m = null;
  161. try {
  162. if(!"".equals(sql) && !"".equals(sql1)){
  163. conn = db.getConnection();
  164. conn.setAutoCommit(false);
  165. ps1 = conn.prepareStatement(sql1);
  166. log.info(report_id+"=========report_id");
  167. log.info(route_level+"=========route_level");
  168. ps1.setString(1, report_id);
  169. ps1.setString(2, route_level);
  170. ps1.executeUpdate();
  171. int num = 0;
  172. m = new Msg();
  173. ps = conn.prepareStatement(sql);
  174. log.info(list.size()+"==================");
  175. for(int i=0;i<list.size();i++){
  176. Map<String, String> map = list.get(i);
  177. if("1".equals(type)){
  178. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  179. ps.setString(2, report_id);
  180. ps.setString(3, map.get("ROUTE_NAME"));
  181. ps.setString(4, map.get("ROUTE_LEVEL"));
  182. ps.setString(5, comp_id);
  183. /* ps.setString(6, map.get("OFLINE_STAT"));*/
  184. ps.setString(6, date);
  185. ps.setString(7, "0");
  186. ps.setString(8, map.get("COMP_NAME"));
  187. ps.setString(9, map.get("END_TIME"));
  188. ps.setString(10, map.get("GZ_TYPE"));
  189. ps.setString(11, map.get("START_TIME"));
  190. ps.setString(12, map.get("LOSS_LOAD"));
  191. ps.setString(13, map.get("COUNT"));
  192. ps.setString(14, map.get("OFLINE_STAT_QK"));
  193. ps.setString(15, route_level);
  194. ps.executeUpdate();
  195. }/*else if("2".equals(type)){
  196. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  197. ps.setString(2, report_id);
  198. ps.setString(3, map.get("STATION_NAME"));
  199. ps.setString(4, map.get("ROUTE_LEVEL"));
  200. ps.setString(5, map.get("COMP_NAME"));
  201. ps.setString(6, map.get("STOP_TIME"));
  202. ps.setString(7, map.get("FAIL_COUNT"));
  203. ps.setString(8, map.get("START_TIME"));
  204. ps.setString(9, "0");
  205. ps.setString(10, date);
  206. ps.setString(11, comp_id);
  207. ps.setString(12, route_level);
  208. ps.executeUpdate();
  209. }*/else if("3".equals(type)){
  210. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  211. ps.setString(2, report_id);
  212. ps.setString(3, route_level);
  213. ps.setString(4, comp_id);
  214. ps.setString(5, map.get("SB_NAME"));
  215. ps.setString(6, map.get("FAIL_TYPE"));
  216. ps.setString(7, map.get("END_TIME"));
  217. ps.setString(8, map.get("START_TIME"));
  218. ps.setString(9, map.get("FAIL_COUNT"));
  219. ps.setString(10, "0");
  220. ps.setString(11, date);
  221. ps.setString(12, map.get("COMP_NAME"));
  222. ps.executeUpdate();
  223. }else if("5".equals(type)){
  224. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  225. ps.setString(2, report_id);
  226. ps.setString(3, comp_id);
  227. ps.setString(4, route_level);
  228. ps.setString(5, map.get("CLIENT_NUMBER"));
  229. ps.setString(6, map.get("CLIENT_NAME"));
  230. ps.setString(7, map.get("CLIENT_LEVEL"));
  231. ps.setString(8, map.get("SUPPORT_STATION"));
  232. ps.setString(9, map.get("STOP_TIME"));
  233. ps.setString(10,map.get("IS_HAD"));
  234. ps.setString(11,map.get("0"));
  235. ps.setString(12,date);
  236. ps.setString(13, map.get("ROUTE_LEVEL"));
  237. ps.executeUpdate();
  238. }else if("8".equals(type)){
  239. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  240. ps.setString(2, report_id);
  241. ps.setString(3, comp_id);
  242. ps.setString(4, route_level);
  243. // ps.setString(5, map.get("COMP_NAME")==""?"0":);
  244. log.info(map.get("SD_CIRCUIT").equals("")+"======null");
  245. ps.setString(5, "".equals(map.get("SD_POWER_CABLE"))?"0":map.get("SD_POWER_CABLE"));
  246. ps.setString(6, "".equals(map.get("SD_CIRCUIT"))?"0":map.get("SD_CIRCUIT"));
  247. ps.setString(7, "".equals(map.get("BD_FIRST"))?"0":map.get("BD_FIRST"));
  248. ps.setString(8, "".equals(map.get("BD_SECOND"))?"0":map.get("BD_SECOND"));
  249. ps.setString(9,"".equals(map.get("PD_CIRCUIT"))?"0":map.get("PD_CIRCUIT"));
  250. ps.setString(10,"".equals(map.get("PD_POWER_CABLE"))?"0":map.get("PD_POWER_CABLE"));
  251. ps.setString(11,"".equals(map.get("DY_STATION"))?"0":map.get("DY_STATION"));
  252. ps.setString(12,"".equals(map.get("YJ_BD")) ?"0":map.get("YJ_BD"));
  253. ps.setString(13, "".equals(map.get("COMMUNICATION"))?"0":map.get("COMMUNICATION"));
  254. ps.setString(14, "".equals(map.get("INTER_INFO"))?"0":map.get("INTER_INFO"));
  255. ps.setString(15, "".equals(map.get("TEST"))?"0":map.get("TEST"));
  256. ps.setString(16,map.get("TOTAL"));
  257. ps.setString(17, "0");
  258. ps.setString(18, date);
  259. ps.executeUpdate();
  260. }else if("4".equals(type)){
  261. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(338));
  262. ps.setString(2, report_id);
  263. ps.setString(3, comp_id);
  264. ps.setString(4, route_level);
  265. ps.setString(5, date);
  266. ps.setString(6, "0");
  267. ps.setString(7, map.get("NAME"));
  268. ps.setString(8, map.get("VOLTAGE"));
  269. ps.setString(9, map.get("TRANSFORMER_NAME"));
  270. ps.setString(10,map.get("DEVICE_TYPE"));
  271. ps.setString(11,map.get("DAMAGE_TYPE"));
  272. ps.setString(12,map.get("LENGTH"));
  273. ps.setString(13,map.get("COUNT"));
  274. ps.setString(14, map.get("IS_REPAIR"));
  275. ps.executeUpdate();
  276. }
  277. num++;
  278. }
  279. if(num==list.size()){
  280. conn.commit();
  281. m.setSucsess(new Boolean(true).toString());
  282. m.setInfo(Parameter.CREATE_SUCSESS);
  283. }else{
  284. conn.rollback();
  285. m.setSucsess(new Boolean(false).toString());
  286. m.setInfo(Parameter.CREATE_FAILURE);
  287. }
  288. }
  289. } catch (SQLException e) {
  290. log.error(e.getMessage(),e);
  291. }finally{
  292. db.close(ps1);
  293. db.close(ps);
  294. db.close(conn);
  295. }
  296. if(m!=null){
  297. return m;
  298. }else{
  299. return null;
  300. }
  301. }
  302. public String getOperateSql(String type){
  303. String sql = "";
  304. String sql1 = "";
  305. if("1".equals(type)){
  306. sql = "insert into route_ofline_detail(fd_objectid,report_id,route_name,route_level,comp_id,updatedate,is_del,"
  307. + "comp_name,end_time,gz_type,start_time,loss_load,count,ofline_stat_qk,types) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  308. sql1 = "delete from route_ofline_detail where report_id = ? and types = ?";
  309. }/*else if("2".equals(type)){
  310. 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(?,?,?,?,?,?,?,?,?,?,?,?)";
  311. sql1 = "delete from bdz_xq_detail where report_id = ? and types = ?";
  312. }*/else if("3".equals(type)){
  313. 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(?,?,?,?,?,?,?,?,?,?,?,?) ";
  314. sql1 = "delete from xldg_xq_detail where report_id = ? and types = ?";
  315. }else if("5".equals(type)){
  316. 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(?,?,?,?,?,?,?,?,?,?,?,?,?)";
  317. sql1 = "delete from tdqk_xq_detail where report_id = ? and types = ?";
  318. }else if("8".equals(type)){
  319. 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)"
  320. + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  321. sql1 = "delete from yjzy_xq_detail where report_id = ? and types = ? ";
  322. }else if("4".equals(type)){
  323. 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(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  324. sql1 ="delete from shousun_detail where report_id = ? and types = ?";
  325. }
  326. return sql+"|"+sql1;
  327. }
  328. public String getClassIdByType(String report_type){
  329. String sql = "select classid from detail_dictionary where report_type = ?";
  330. String result = "";
  331. try {
  332. List<String[]> list= new ORGTemplate().getSearchResult(sql, report_type);
  333. result = list.get(0)[0];
  334. } catch (SQLException e) {
  335. log.info(e.getMessage(),e);
  336. }
  337. return result;
  338. }
  339. }