SysNotifyTodoWebServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package com.uas.service.Impl;
  2. import com.landray.kmss.sys.notify.webservice.ISysNotifyTodoWebService;
  3. import com.landray.kmss.sys.notify.webservice.NotifyTodoAppResult;
  4. import com.landray.kmss.sys.notify.webservice.NotifyTodoGetContext;
  5. import com.uas.core.config.AddSoapHeader;
  6. import com.uas.core.config.WebServiceConfig;
  7. import com.uas.dao.BaseDao;
  8. import com.uas.dao.SqlRowList;
  9. import com.uas.service.SysNotifyTodoWebService;
  10. import net.sf.json.JSONArray;
  11. import net.sf.json.JSONObject;
  12. import org.apache.cxf.interceptor.LoggingInInterceptor;
  13. import org.apache.cxf.interceptor.LoggingOutInterceptor;
  14. import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * @author koul
  21. * @email koul@usoftchina.com
  22. * @date 2021-05-19 10:00
  23. */
  24. @Service
  25. public class SysNotifyTodoWebServiceImpl implements SysNotifyTodoWebService {
  26. @Autowired
  27. BaseDao baseDao;
  28. /**
  29. * 获取待办接入 WebService 对象
  30. * @return
  31. */
  32. private ISysNotifyTodoWebService getService(){
  33. // 定义组织架构接入 WebService 对象
  34. ISysNotifyTodoWebService setNotifyWebService=null;
  35. if(setNotifyWebService==null){
  36. // WebService 配置信息对象(读取自 client.properties 配置文件)
  37. WebServiceConfig serviceConfig = WebServiceConfig.getInstance();
  38. // 使用 Apache CXF 框架创建组织架构接入 WebService 对象
  39. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  40. factory.getInInterceptors().add(new LoggingInInterceptor());
  41. factory.getOutInterceptors().add(new LoggingOutInterceptor());
  42. factory.getOutInterceptors().add(new AddSoapHeader());
  43. factory.setServiceClass(serviceConfig.getNotifyServiceClass());
  44. // 设置服务请求的 URL 地址
  45. String servicePath = serviceConfig.getNotifyAddress();
  46. factory.setAddress(servicePath);
  47. setNotifyWebService = (ISysNotifyTodoWebService) factory.create();
  48. }
  49. return setNotifyWebService;
  50. }
  51. /**
  52. *
  53. * @param setContext 信息接入上下文
  54. * @return
  55. * @throws Exception
  56. */
  57. private NotifyTodoAppResult syncNotifyData(NotifyTodoGetContext setContext) throws Exception{
  58. return getService().getTodo(setContext);
  59. }
  60. /**
  61. * 获取待办/已办
  62. * @return
  63. */
  64. @Override
  65. public void getNotifyData(){
  66. SqlRowList persons = baseDao.queryForRowSet("select row_number() over (order by em_id) rn,em_id,em_code,em_name,em_password,em_mobile, em_email,em_cardcode,em_departmentcode,em_depart,em_position,em_defaulthsid from employee where em_class<>'离职' and nvl(em_islandray,0)=-1 order by em_id");
  67. while (persons.next()) {
  68. JSONObject personObj = new JSONObject();
  69. // ERP标识
  70. personObj.put("LoginName", persons.getString("em_mobile"));
  71. getTodoData(personObj.toString(),persons.getString("em_code"));
  72. getAlreadyData(personObj.toString(),persons.getString("em_code"));
  73. }
  74. }
  75. private String getTodoData(String person,String cond) {
  76. String res = "";
  77. // 定义组织架构信息接入上下文
  78. NotifyTodoGetContext context = new NotifyTodoGetContext();
  79. // 获取测试组织数据
  80. /*JSONArray jsonData = getJsonData();*/
  81. // 将组织数据设置到组织架构信息接入上下文
  82. context.setTargets(person);
  83. context.setType(1);
  84. /*context.setOtherCond(cond);*/
  85. try {
  86. // 调用 WebService 接口,并接收请求返回的数据
  87. NotifyTodoAppResult result = syncNotifyData(context);
  88. if (result.getReturnState()==0){
  89. res="蓝凌OA待办下载失败,接口异常";
  90. }else if (result.getReturnState()==1){
  91. res="蓝凌OA待办下载失败,失败信息:"+result.getMessage();
  92. }else if (result.getReturnState()==2){
  93. String message = result.getMessage();
  94. List<String> sqls = new ArrayList<>();
  95. baseDao.execute("delete from jprocess where nvl(jp_landrayid,' ')<>' ' and jp_status='待审批' and " +
  96. "jp_nodedealman='"+cond+"'");
  97. if (message.indexOf("errorPage")==-1) {
  98. JSONObject jsonObject = JSONObject.fromObject(message);
  99. JSONArray docs = jsonObject.getJSONArray("docs");
  100. for (int i = 0; i < docs.size(); i++) {
  101. Object obj = docs.get(i);
  102. JSONObject object = JSONObject.fromObject(obj);
  103. String link = object.get("link") == null ? null : object.getString("link").replace("&", "'||chr(38)||'");
  104. sqls.add("insert into jprocess(jp_id, jp_name, jp_launcherid, jp_launchername, jp_form, " +
  105. "jp_launchtime, jp_table, jp_status, jp_url,jp_landrayid,jp_nodedealman,jp_codevalue," +
  106. "jp_processinstanceid,jp_nodename) values(process_seq.nextval,'" + object.getString("subject") + "','" + object.getString("creator") + "','" +
  107. object.getString("creatorName") + "','" + object.getString("key") + "',to_date('" + object.getString("createTime") + "','yyyy-MM-dd HH24:mi:ss'),'" +
  108. object.getString("modelName") + "','待审批','http://oa.seg.com.cn:8081" + link + "','" + object.getString("id") + "','" + cond + "','" + object.getString("moduleName") + "','" + object.getString("id") + "','" + cond + "')");
  109. }
  110. }
  111. //else {
  112. // SqlRowList rowSet = baseDao.queryForRowSet("select jp_processinstanceid from jprocess where nvl(jp_landrayid,' ')<>' ' and jp_status='待审批' and jp_nodedealman='" + cond + "'");
  113. // while (rowSet.next()) {
  114. // sqls.add("update jprocess set jp_status='已审批' where nvl(jp_landrayid,' ')<>' ' and jp_nodedealman='" + cond + "' and jp_processinstanceid='"+rowSet.getString("jp_processinstanceid")+"'");
  115. // baseDao.execute("insert into jnode (jn_id,jn_name, jn_dealmanid,jn_processinstanceid,JN_DEALTIME, JN_DEALRESULT) values (jnode_seq.nextval,'" + cond + "','" + cond + "','" + rowSet.getString("jp_processinstanceid") + "',to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'详见蓝凌OA')");
  116. // }
  117. // }
  118. if (sqls != null && sqls.size() > 0) {
  119. baseDao.execute(sqls);
  120. }
  121. res = "蓝凌OA待办下载成功";
  122. }
  123. } catch (Exception e) {
  124. res="蓝凌OA待办下载失败,接口异常,异常信息:"+e.getMessage();
  125. e.printStackTrace();
  126. }
  127. return res;
  128. }
  129. private String getAlreadyData(String person,String cond) {
  130. String res = "";
  131. // 定义组织架构信息接入上下文
  132. NotifyTodoGetContext context = new NotifyTodoGetContext();
  133. // 获取测试组织数据
  134. /*JSONArray jsonData = getJsonData();*/
  135. // 将组织数据设置到组织架构信息接入上下文
  136. context.setTargets(person);
  137. context.setType(4);
  138. /*context.setOtherCond(cond);*/
  139. try {
  140. // 调用 WebService 接口,并接收请求返回的数据
  141. NotifyTodoAppResult result = syncNotifyData(context);
  142. if (result.getReturnState()==0){
  143. res="蓝凌OA已办下载失败,接口错误";
  144. }else if (result.getReturnState()==1){
  145. res="蓝凌OA已办下载失败,失败信息:"+result.getMessage();
  146. }else if (result.getReturnState()==2){
  147. String message = result.getMessage();
  148. if (message.indexOf("errorPage")==-1) {
  149. JSONObject jsonObject = JSONObject.fromObject(message);
  150. JSONArray docs = jsonObject.getJSONArray("docs");
  151. List<String> sqls = new ArrayList<>();
  152. for (int i = 0; i < docs.size(); i++) {
  153. Object obj = docs.get(i);
  154. JSONObject object = JSONObject.fromObject(obj);
  155. String link = object.get("link") == null ? null : object.getString("link").replace("&", "'||chr(38)||'");
  156. if (baseDao.getCountByCondition("jprocess", "jp_landrayid='" + object.getString("id") + "'") == 0) {
  157. sqls.add("insert into jprocess(jp_id, jp_name, jp_launcherid, jp_launchername, jp_form, " +
  158. "jp_launchtime, jp_table, jp_status, jp_url,jp_landrayid,jp_nodedealman,jp_codevalue," +
  159. "jp_processinstanceid,jp_nodename) values (process_seq.nextval,'" + object.getString("subject") + "','" + object.getString("creator") + "','" +
  160. object.getString("creatorName") + "','" + object.getString("key") + "',to_date('" + object.getString("createTime") + "','yyyy-MM-dd HH24:mi:ss'),'" +
  161. object.getString("modelName") + "','已审批','http://oa.seg.com.cn:8081" + link + "','" + object.getString("id") + "','" + cond + "','" + object.getString("moduleName") + "','" + object.getString("id") + "','" + cond + "')");
  162. sqls.add("insert into jnode (jn_id,jn_name, jn_dealmanid,jn_processinstanceid,JN_DEALTIME, JN_DEALRESULT) values" +
  163. "(jnode_seq.nextval,'" + cond + "','" + cond + "','" + object.getString("id") + "',to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'详见蓝凌OA')");
  164. } else {
  165. if (baseDao.getCountByCondition("jprocess", "jp_status='待审批' and jp_landrayid='" + object.getString("id") + "'") > 0) {
  166. sqls.add("update jprocess set jp_status='已审批' where jp_landrayid='" + object.getString("id") + "'");
  167. sqls.add("insert into jnode (jn_id,jn_name, jn_dealmanid,jn_processinstanceid,JN_DEALTIME, JN_DEALRESULT) values " +
  168. "(jnode_seq.nextval,'" + cond + "','" + cond + "','" + object.getString("id") +
  169. "',to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'详见蓝凌OA')");
  170. }
  171. }
  172. }
  173. if (sqls != null && sqls.size() > 0) {
  174. baseDao.execute(sqls);
  175. }
  176. res = "蓝凌OA已办下载成功";
  177. }
  178. }
  179. System.err.println(res);
  180. } catch (Exception e) {
  181. res="蓝凌OA已办下载失败,接口异常,异常信息:"+e.getMessage();
  182. e.printStackTrace();
  183. }
  184. System.err.println(res);
  185. return res;
  186. }
  187. }