3d6e94149b97a0a1dc38895cb567e4be06357c65.svn-base 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package com.sinosoft.nwyj.integration.hessian;
  2. import java.io.InputStream;
  3. import java.net.MalformedURLException;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.GregorianCalendar;
  7. import java.util.List;
  8. import java.util.Properties;
  9. import javax.ws.rs.POST;
  10. import javax.ws.rs.Path;
  11. import javax.ws.rs.ProduceMime;
  12. import javax.xml.datatype.DatatypeConfigurationException;
  13. import javax.xml.datatype.DatatypeFactory;
  14. import org.aspectj.lang.JoinPoint;
  15. import org.aspectj.lang.annotation.Aspect;
  16. import org.aspectj.lang.annotation.Before;
  17. import org.springframework.stereotype.Component;
  18. import com.caucho.hessian.client.HessianProxyFactory;
  19. import com.formaction.Utils;
  20. import com.persistence.service.JDBCHelper;
  21. import com.persistence.service.exception.PersistenceException;
  22. import com.sinosoft.common.util.DateUtil;
  23. import com.sinosoft.nwyj.integration.cxf.dc.querySingleTabData.QuerySingleTabDataRequest;
  24. import com.sinosoft.nwyj.integration.cxf.dc.querySingleTabData.QuerySingleTabDataResponse;
  25. import com.sinosoft.nwyj.integration.cxf.powerSupplyTask.PowerSupplyTask;
  26. @Aspect
  27. @Component
  28. public class GpsTaskWebService {
  29. @Before("execution(* com.formaction.service.CRUDServiceImpl.update(..))")
  30. public void PublishPowerSupplyTask(JoinPoint joinPoint) {
  31. // 取得参数
  32. String params = (String) joinPoint.getArgs()[0];
  33. String taskPublish = Utils.getParameter("taskPublish", params) == null ? ""
  34. : Utils.getParameter("taskPublish", params);
  35. // 需要调用webservice
  36. if (!taskPublish.equals("")) {
  37. // 保供电id
  38. String id = Utils.getParameter("FD_OBJECTID610", params) == null ? ""
  39. : Utils.getParameter("FD_OBJECTID610", params);
  40. String url = getPath("path") + "/hessian/hessianService";
  41. HessianProxyFactory factory = new HessianProxyFactory();
  42. HessianService hs;
  43. try {
  44. hs = (HessianService) factory.create(HessianService.class, url);
  45. // 取得保供电实体
  46. PowerSupplyTask pst = getPst(id);
  47. hs.PublishPowerSupplyTask(pst);
  48. } catch (MalformedURLException e) {
  49. e.printStackTrace();
  50. } catch (PersistenceException e) {
  51. e.printStackTrace();
  52. } catch (DatatypeConfigurationException e) {
  53. e.printStackTrace();
  54. }
  55. }
  56. }
  57. // 根据保供电id获取保供电任务实体
  58. public PowerSupplyTask getPst(String id) throws PersistenceException, DatatypeConfigurationException {
  59. if (id == null || id.equals("")) {
  60. return null;
  61. }
  62. PowerSupplyTask pst = null;
  63. String sql = "select a.FD_OBJECTID,PROGRAM_NAME,GPS_LEVEL ,GPS_AREA_NAME,START_TIME, END_TIME,IMPLEMENT_TIME,"
  64. + "INPUT_UNIT_ID,b.savename,a.INPUT_UNIT_ID,c.saphrorgid from ECM_GPS_PROGRAM_MANAGEMENT a "
  65. + "left join sys_comm_fileimg b on a.fd_objectid = b.mainid left join sys_department c on c.dept_id=a.INPUT_UNIT_ID " + "where a.fd_objectid ='" + id + "'";
  66. JDBCHelper jdbc = new JDBCHelper();
  67. jdbc.begin();
  68. ArrayList<String[]> list = jdbc.getSearchResult(610, sql);
  69. int i = 0;
  70. String filePath = "";
  71. GregorianCalendar calendar = new GregorianCalendar();
  72. if (list != null && list.size() > 0) {
  73. pst = new PowerSupplyTask();
  74. for (String[] s : list) {
  75. if (i == 0) {
  76. pst.setTaskId(s[0]);
  77. pst.setTaskName(s[1]);
  78. pst.setTaskLevel(s[2]);
  79. Date startDate = DateUtil.format(s[4], DateUtil.formatStr_yyyyMMddHHmmssS);
  80. calendar.setTime(startDate);
  81. pst.setStartDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));// W3C—XML日期格式
  82. Date endDate = DateUtil.format(s[5], DateUtil.formatStr_yyyyMMddHHmmssS);
  83. calendar.setTime(endDate);
  84. pst.setEndDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));// W3C—XML日期格式
  85. Date yearMon = DateUtil.format(s[6], DateUtil.YYYY_MM);
  86. calendar.setTime(yearMon);
  87. pst.setPlanYearMon(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));// W3C—XML日期格式
  88. pst.setPowerSupplyArea(s[7]);
  89. pst.setBusinessCode(s[10]);
  90. }
  91. filePath += s[8] + ";";
  92. i++;
  93. }
  94. if (!filePath.equals("")) {
  95. filePath = filePath.substring(0, filePath.length() - 1);
  96. }
  97. //pst.setDocument(filePath);
  98. }
  99. jdbc.commit();
  100. return pst;
  101. }
  102. // 获取配置的webservice路径的方法
  103. public static String getPath(String key) {
  104. String path = "";
  105. if (key == null || key.equals("")) {
  106. return "";
  107. }
  108. Properties prop = new Properties();
  109. try {
  110. // 读取属性文件a.properties
  111. InputStream in = GpsTaskWebService.class.getClassLoader()
  112. .getResourceAsStream("webserviceProperty.properties");
  113. prop.load(in); /// 加载属性列表
  114. path = prop.getProperty(key);
  115. in.close();
  116. } catch (Exception e) {
  117. System.out.println(e);
  118. }
  119. return path;
  120. }
  121. /**
  122. * 查询95598来电
  123. *
  124. * @param startDate
  125. * 开始时间 yyyy-MM-dd hh24:mm:ss
  126. * @param endDate
  127. * 结束时间yyyy-MM-dd hh24:mm:ss
  128. * @param organizationId
  129. * 组织ID mrid
  130. * @return json数据
  131. */
  132. public String call95598(String startDate, String endDate, List<String> organizationId) {
  133. String url = getPath("path") + "/hessian/hessianService";
  134. HessianProxyFactory factory = new HessianProxyFactory();
  135. HessianService hs;
  136. String jsonResult = null;
  137. try {
  138. hs = (HessianService) factory.create(HessianService.class, url);
  139. jsonResult = hs.calls95598(startDate, endDate, organizationId);
  140. } catch (MalformedURLException e) {
  141. e.printStackTrace();
  142. }
  143. return jsonResult;
  144. }
  145. public String getCSGRDBDataInfo(String compId,String startTime,String endTime){
  146. String url = getPath("path") + "/hessian/hessianService";
  147. HessianProxyFactory factory = new HessianProxyFactory();
  148. HessianService hs;
  149. try {
  150. hs = (HessianService) factory.create(HessianService.class, url);
  151. String jsonStr=hs.getCSGRDBDataInfo(compId, startTime, endTime);
  152. try {
  153. Thread.sleep(500);
  154. } catch (InterruptedException e) {
  155. // TODO Auto-generated catch block
  156. e.printStackTrace();
  157. }
  158. return jsonStr;
  159. } catch (MalformedURLException e) {
  160. e.printStackTrace();
  161. }
  162. return null;
  163. }
  164. /**
  165. * hessian服务:
  166. * 获取设备台账数据
  167. */
  168. public QuerySingleTabDataResponse querySingleTabData(QuerySingleTabDataRequest request){
  169. String url = getPath("path") + "/hessian/hessianService";
  170. HessianProxyFactory factory = new HessianProxyFactory();
  171. HessianService hs;
  172. try {
  173. hs = (HessianService) factory.create(HessianService.class, url);
  174. QuerySingleTabDataResponse response=hs.querySingleTabData(request);
  175. return response;
  176. } catch (MalformedURLException e) {
  177. e.printStackTrace();
  178. }
  179. return null;
  180. }
  181. }