package com.uas.service.Impl; import com.landray.kmss.sys.notify.webservice.ISysNotifyTodoWebService; import com.landray.kmss.sys.notify.webservice.NotifyTodoAppResult; import com.landray.kmss.sys.notify.webservice.NotifyTodoGetContext; import com.uas.core.config.AddSoapHeader; import com.uas.core.config.WebServiceConfig; import com.uas.dao.BaseDao; import com.uas.dao.SqlRowList; import com.uas.service.SysNotifyTodoWebService; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * @author koul * @email koul@usoftchina.com * @date 2021-05-19 10:00 */ @Service public class SysNotifyTodoWebServiceImpl implements SysNotifyTodoWebService { @Autowired BaseDao baseDao; /** * 获取待办接入 WebService 对象 * @return */ private ISysNotifyTodoWebService getService(){ // 定义组织架构接入 WebService 对象 ISysNotifyTodoWebService setNotifyWebService=null; if(setNotifyWebService==null){ // WebService 配置信息对象(读取自 client.properties 配置文件) WebServiceConfig serviceConfig = WebServiceConfig.getInstance(); // 使用 Apache CXF 框架创建组织架构接入 WebService 对象 JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.getOutInterceptors().add(new AddSoapHeader()); factory.setServiceClass(serviceConfig.getNotifyServiceClass()); // 设置服务请求的 URL 地址 String servicePath = serviceConfig.getNotifyAddress(); factory.setAddress(servicePath); setNotifyWebService = (ISysNotifyTodoWebService) factory.create(); } return setNotifyWebService; } /** * * @param setContext 信息接入上下文 * @return * @throws Exception */ private NotifyTodoAppResult syncNotifyData(NotifyTodoGetContext setContext) throws Exception{ return getService().getTodo(setContext); } /** * 获取待办/已办 * @return */ @Override public void getNotifyData(){ 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"); while (persons.next()) { JSONObject personObj = new JSONObject(); // ERP标识 personObj.put("LoginName", persons.getString("em_mobile")); getTodoData(personObj.toString(),persons.getString("em_code")); getAlreadyData(personObj.toString(),persons.getString("em_code")); } } private String getTodoData(String person,String cond) { String res = ""; // 定义组织架构信息接入上下文 NotifyTodoGetContext context = new NotifyTodoGetContext(); // 获取测试组织数据 /*JSONArray jsonData = getJsonData();*/ // 将组织数据设置到组织架构信息接入上下文 context.setTargets(person); context.setType(1); /*context.setOtherCond(cond);*/ try { // 调用 WebService 接口,并接收请求返回的数据 NotifyTodoAppResult result = syncNotifyData(context); if (result.getReturnState()==0){ res="蓝凌OA待办下载失败,接口异常"; }else if (result.getReturnState()==1){ res="蓝凌OA待办下载失败,失败信息:"+result.getMessage(); }else if (result.getReturnState()==2){ String message = result.getMessage(); List sqls = new ArrayList<>(); baseDao.execute("delete from jprocess where nvl(jp_landrayid,' ')<>' ' and jp_status='待审批' and " + "jp_nodedealman='"+cond+"'"); if (message.indexOf("errorPage")==-1) { JSONObject jsonObject = JSONObject.fromObject(message); JSONArray docs = jsonObject.getJSONArray("docs"); for (int i = 0; i < docs.size(); i++) { Object obj = docs.get(i); JSONObject object = JSONObject.fromObject(obj); String link = object.get("link") == null ? null : object.getString("link").replace("&", "'||chr(38)||'"); sqls.add("insert into jprocess(jp_id, jp_name, jp_launcherid, jp_launchername, jp_form, " + "jp_launchtime, jp_table, jp_status, jp_url,jp_landrayid,jp_nodedealman,jp_codevalue," + "jp_processinstanceid,jp_nodename) values(process_seq.nextval,'" + object.getString("subject") + "','" + object.getString("creator") + "','" + object.getString("creatorName") + "','" + object.getString("key") + "',to_date('" + object.getString("createTime") + "','yyyy-MM-dd HH24:mi:ss'),'" + object.getString("modelName") + "','待审批','http://oa.seg.com.cn:8081" + link + "','" + object.getString("id") + "','" + cond + "','" + object.getString("moduleName") + "','" + object.getString("id") + "','" + cond + "')"); } } //else { // SqlRowList rowSet = baseDao.queryForRowSet("select jp_processinstanceid from jprocess where nvl(jp_landrayid,' ')<>' ' and jp_status='待审批' and jp_nodedealman='" + cond + "'"); // while (rowSet.next()) { // sqls.add("update jprocess set jp_status='已审批' where nvl(jp_landrayid,' ')<>' ' and jp_nodedealman='" + cond + "' and jp_processinstanceid='"+rowSet.getString("jp_processinstanceid")+"'"); // 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')"); // } // } if (sqls != null && sqls.size() > 0) { baseDao.execute(sqls); } res = "蓝凌OA待办下载成功"; } } catch (Exception e) { res="蓝凌OA待办下载失败,接口异常,异常信息:"+e.getMessage(); e.printStackTrace(); } return res; } private String getAlreadyData(String person,String cond) { String res = ""; // 定义组织架构信息接入上下文 NotifyTodoGetContext context = new NotifyTodoGetContext(); // 获取测试组织数据 /*JSONArray jsonData = getJsonData();*/ // 将组织数据设置到组织架构信息接入上下文 context.setTargets(person); context.setType(4); /*context.setOtherCond(cond);*/ try { // 调用 WebService 接口,并接收请求返回的数据 NotifyTodoAppResult result = syncNotifyData(context); if (result.getReturnState()==0){ res="蓝凌OA已办下载失败,接口错误"; }else if (result.getReturnState()==1){ res="蓝凌OA已办下载失败,失败信息:"+result.getMessage(); }else if (result.getReturnState()==2){ String message = result.getMessage(); if (message.indexOf("errorPage")==-1) { JSONObject jsonObject = JSONObject.fromObject(message); JSONArray docs = jsonObject.getJSONArray("docs"); List sqls = new ArrayList<>(); for (int i = 0; i < docs.size(); i++) { Object obj = docs.get(i); JSONObject object = JSONObject.fromObject(obj); String link = object.get("link") == null ? null : object.getString("link").replace("&", "'||chr(38)||'"); if (baseDao.getCountByCondition("jprocess", "jp_landrayid='" + object.getString("id") + "'") == 0) { sqls.add("insert into jprocess(jp_id, jp_name, jp_launcherid, jp_launchername, jp_form, " + "jp_launchtime, jp_table, jp_status, jp_url,jp_landrayid,jp_nodedealman,jp_codevalue," + "jp_processinstanceid,jp_nodename) values (process_seq.nextval,'" + object.getString("subject") + "','" + object.getString("creator") + "','" + object.getString("creatorName") + "','" + object.getString("key") + "',to_date('" + object.getString("createTime") + "','yyyy-MM-dd HH24:mi:ss'),'" + object.getString("modelName") + "','已审批','http://oa.seg.com.cn:8081" + link + "','" + object.getString("id") + "','" + cond + "','" + object.getString("moduleName") + "','" + object.getString("id") + "','" + cond + "')"); sqls.add("insert into jnode (jn_id,jn_name, jn_dealmanid,jn_processinstanceid,JN_DEALTIME, JN_DEALRESULT) values" + "(jnode_seq.nextval,'" + cond + "','" + cond + "','" + object.getString("id") + "',to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'详见蓝凌OA')"); } else { if (baseDao.getCountByCondition("jprocess", "jp_status='待审批' and jp_landrayid='" + object.getString("id") + "'") > 0) { sqls.add("update jprocess set jp_status='已审批' where jp_landrayid='" + object.getString("id") + "'"); sqls.add("insert into jnode (jn_id,jn_name, jn_dealmanid,jn_processinstanceid,JN_DEALTIME, JN_DEALRESULT) values " + "(jnode_seq.nextval,'" + cond + "','" + cond + "','" + object.getString("id") + "',to_char(sysdate,'yyyy-MM-dd HH24:mi:ss'),'详见蓝凌OA')"); } } } if (sqls != null && sqls.size() > 0) { baseDao.execute(sqls); } res = "蓝凌OA已办下载成功"; } } System.err.println(res); } catch (Exception e) { res="蓝凌OA已办下载失败,接口异常,异常信息:"+e.getMessage(); e.printStackTrace(); } System.err.println(res); return res; } }