|
@@ -1,299 +0,0 @@
|
|
|
-package fi.oa;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import org.apache.http.HttpResponse;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
-import kd.bos.dataentity.entity.DynamicObject;
|
|
|
-import kd.bos.orm.query.QCP;
|
|
|
-import kd.bos.orm.query.QFilter;
|
|
|
-import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
-import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
-import kd.bos.workflow.engine.msg.AbstractMessageServiceHandler;
|
|
|
-import kd.bos.workflow.engine.msg.ctx.MessageContext;
|
|
|
-import kd.bos.workflow.engine.msg.info.ToDoInfo;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.http.client.methods.HttpPost;
|
|
|
-import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
-import org.apache.http.message.BasicHeader;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.rmi.ConnectException;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import static cfca.org.bouncycastle.util.encoders.Base64.encode;
|
|
|
-
|
|
|
-public class DaiBanServiceHandler extends AbstractMessageServiceHandler {
|
|
|
-
|
|
|
- private static final Logger log = LoggerFactory.getLogger(fi.oa.DaiBanServiceHandler.class);
|
|
|
-
|
|
|
- /**
|
|
|
- * 人员表标识
|
|
|
- */
|
|
|
- private static final String USER_FORM_ID = "bos_user";
|
|
|
-
|
|
|
- private static final String sendUrl = "/ekp/api/sys-notify/sysNotifyTodoRestService/sendTodo";//发送待办
|
|
|
-
|
|
|
- private static final String dealUrl = "/ekp/api/sys-notify/sysNotifyTodoRestService/setTodoDone";//设为已办
|
|
|
-
|
|
|
- private static final String deleteUrl = "/ekp/api/sys-notify/sysNotifyTodoRestService/deleteTodo";//删除待办
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void createToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
|
|
- log.info("推送待办开始 ctx: " + messageContext.toString() + ",taskId:" + messageContext.getTaskId());
|
|
|
-
|
|
|
-
|
|
|
- List<Long> userIds = toDoInfo.getUserIds();
|
|
|
- if (CollectionUtils.isEmpty(userIds)) {
|
|
|
- log.info("人员为空,推送失败");
|
|
|
- return;
|
|
|
- }
|
|
|
- QFilter qFilter = new QFilter("id", QCP.in, userIds);
|
|
|
- DynamicObject[] load = BusinessDataServiceHelper.load(USER_FORM_ID, "number", qFilter.toArray());
|
|
|
-
|
|
|
- DynamicObject taskInfo = BusinessDataServiceHelper.loadSingleFromCache(toDoInfo.getTaskId() ,"wf_task");
|
|
|
- String status="PENDING";
|
|
|
-
|
|
|
- if("willApproval".equals(taskInfo.getString("handlestate"))){//待审批
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- JSONObject m = getToDaiBanJson(toDoInfo,load);
|
|
|
- try {
|
|
|
- doPostByHttpClient(sendUrl, m.toString());
|
|
|
- log.info("正邦门户云苍穹飞书推送待办:"+m.toJSONString());
|
|
|
- String response = doPostByHttpClient(sendUrl, m.toJSONString());
|
|
|
- log.info("正邦门户云苍穹飞书推送待办结果:"+response);
|
|
|
- JSONObject instanceRes = JSONObject.parseObject(response);
|
|
|
- } catch (ConnectException e) {
|
|
|
- log.info("正邦门户云苍穹飞书,推送失败");
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取创建审批实例json
|
|
|
- * @return
|
|
|
- */
|
|
|
- public JSONObject getToDaiBanJson(ToDoInfo toDoInfo,DynamicObject[] load){
|
|
|
- boolean isExist = QueryServiceHelper.exists("wf_task",toDoInfo.getTaskId());
|
|
|
- if(!isExist){
|
|
|
-// return getdeleteJson(messageContext,toDoInfo,load,isUpdate,passStatus,content,toDoInfo.getTaskId()+"");
|
|
|
- }
|
|
|
- DynamicObject taskInfo = BusinessDataServiceHelper.loadSingle(toDoInfo.getTaskId() ,"wf_task");
|
|
|
-
|
|
|
-
|
|
|
- JSONObject m = new JSONObject(true);
|
|
|
- JSONObject docCreator = new JSONObject(true);
|
|
|
- m.put("appName","ycq");//待办来源
|
|
|
- m.put("modelName",taskInfo.getString("entityname"));//模块名
|
|
|
- m.put("modelId", toDoInfo.getTaskId());//待办唯一标识
|
|
|
- m.put("subjec", toDoInfo.getContent());//标题
|
|
|
-
|
|
|
-
|
|
|
- m.put("link", toDoInfo.getUrl());//链接
|
|
|
- m.put("mobileLink", toDoInfo.getUrl());//移动端链接
|
|
|
- m.put("padLink", toDoInfo.getUrl());//pad端链接
|
|
|
- m.put("type", 1);//待办类型
|
|
|
- m.put("key", "");//关键字
|
|
|
- m.put("param1", "");//关键字
|
|
|
- m.put("param2", "");//关键字
|
|
|
-
|
|
|
- if (load.length > 1) {
|
|
|
- JSONArray targets = new JSONArray();
|
|
|
- for (int i = 0; i < load.length; i++) {
|
|
|
- String number = load[i].getString("number");
|
|
|
- JSONObject element = new JSONObject(true);
|
|
|
- element.put("PersonNo", number);
|
|
|
- targets.add(element);
|
|
|
- }
|
|
|
- m.put("targets", targets);//待办所属对象
|
|
|
- }else {
|
|
|
- JSONObject targets = new JSONObject(true);
|
|
|
- targets.put("PersonNo", load[0].getString("number"));
|
|
|
- m.put("targets", targets);//待办所属对象
|
|
|
- }
|
|
|
-
|
|
|
- m.put("createTime", taskInfo.getDate("createdate"));//创建时间
|
|
|
-
|
|
|
-
|
|
|
- Long faqirenid = taskInfo.getLong("starterid");
|
|
|
- if(faqirenid!=null){
|
|
|
- DynamicObject faqiren = BusinessDataServiceHelper.loadSingleFromCache(faqirenid,"bos_user");
|
|
|
- docCreator.put("PersonNo", faqiren.getString("number"));//待办创建者
|
|
|
- }
|
|
|
- m.put("docCreator", docCreator);//待办创建者
|
|
|
- m.put("level", "");//待办优先级
|
|
|
- m.put("extendContent", "");//消息内容扩展
|
|
|
- m.put("others", "");//扩展参数
|
|
|
- m.put("fdPreviousHandlerNum", "");//上一处理人登录账号
|
|
|
- m.put("fdPreviousHandlerName", taskInfo.getString("sendernameformat"));//上一处理人的名字
|
|
|
- m.put("fdCurrentNode", "");//当前环节(人员账号)
|
|
|
- m.put("fdCurrentNodeName", taskInfo.getString("name"));//当前环节(名称)
|
|
|
- return m;
|
|
|
- }
|
|
|
-
|
|
|
- public static String doPostByHttpClient(String url, String data) throws ConnectException {
|
|
|
- System.out.println("url =" + url);
|
|
|
- System.out.println("data =" + data);
|
|
|
- try {
|
|
|
- DefaultHttpClient httpClient = new DefaultHttpClient();
|
|
|
- HttpPost httpPost = new HttpPost(url);
|
|
|
- // 如果EKP对该接口启用了Basic认证,那么客户端需要加入认证header信息
|
|
|
- String accountID = "admin"; // 认证用户名
|
|
|
- String accountPassword = "123456"; // 认证密码
|
|
|
- byte[] encodedAuth = encode((accountID+":"+accountPassword).getBytes(StandardCharsets.UTF_8));
|
|
|
- String authHeader = "Basic " + new String( encodedAuth );
|
|
|
-
|
|
|
- httpPost.addHeader("Content-Type", "application/json; charset=UTF-8");
|
|
|
- httpPost.addHeader("Authorization", authHeader);
|
|
|
-
|
|
|
-
|
|
|
- StringEntity se = new StringEntity(data, "UTF-8");
|
|
|
- se.setContentType("text/json");
|
|
|
- se.setContentEncoding(new BasicHeader("Content-Type", "application/json; charset=UTF-8"));
|
|
|
- httpPost.setEntity(se);
|
|
|
- HttpResponse response = httpClient.execute(httpPost);
|
|
|
- int statusCode = response.getStatusLine().getStatusCode();
|
|
|
- if (statusCode != 200) {
|
|
|
- throw new ConnectException("连接服务器发生错误!");
|
|
|
- }
|
|
|
- String body = EntityUtils.toString(response.getEntity());
|
|
|
- return body;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- System.out.println(" ===== doPostByHttpClient() ERROR ===== ");
|
|
|
- throw new ConnectException(e.getMessage());
|
|
|
- } finally {
|
|
|
- System.clearProperty("javax.net.debug");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void dealToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
|
|
- log.info("更新待办为已办开始 ctx: " + messageContext.toString() + ",taskId:" + messageContext.getTaskId());
|
|
|
- try {
|
|
|
- List<Long> userIds = toDoInfo.getUserIds();
|
|
|
- if (CollectionUtils.isEmpty(userIds)) {
|
|
|
- log.info("人员为空,推送失败");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- log.info("获取用户开始");
|
|
|
- QFilter qFilter = new QFilter("id", QCP.in, userIds);
|
|
|
- DynamicObject[] load = BusinessDataServiceHelper.load(USER_FORM_ID, "number", qFilter.toArray());
|
|
|
- log.info("获取用户结束:"+load[0].getPkValue());
|
|
|
-
|
|
|
- log.info("获取任务:");
|
|
|
- boolean isExist = QueryServiceHelper.exists("wf_task",toDoInfo.getTaskId());
|
|
|
- if(isExist){
|
|
|
- DynamicObject taskInfo = BusinessDataServiceHelper.loadSingleFromCache(toDoInfo.getTaskId() ,"wf_task");
|
|
|
- log.info("获取任务结束:"+taskInfo.getPkValue());
|
|
|
- JSONObject m = getToYiBanJson(toDoInfo,load,taskInfo);
|
|
|
- doPostByHttpClient(dealUrl, m.toString());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("更新待办失败" + e.getMessage());
|
|
|
- log.info(e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取创建审批实例json
|
|
|
- * @return
|
|
|
- */
|
|
|
- public JSONObject getToYiBanJson(ToDoInfo toDoInfo,DynamicObject[] load, DynamicObject taskInfo){
|
|
|
- JSONObject m = new JSONObject(true);
|
|
|
- m.put("appName","ycq");//待办来源
|
|
|
- m.put("modelName",taskInfo.getString("entityname"));//模块名
|
|
|
- m.put("modelId", toDoInfo.getTaskId());//待办唯一标识
|
|
|
- m.put("optType", 2);//操作类型(1:表示设待办为已办操作,2:表示设置目标待办所属人为已办操作)
|
|
|
- m.put("param1", null);//关键字
|
|
|
- m.put("param2", null);//关键字
|
|
|
- m.put("type", null);//关键字
|
|
|
-
|
|
|
- if (load.length > 1) {
|
|
|
- JSONArray targets = new JSONArray();
|
|
|
- for (int i = 0; i < load.length; i++) {
|
|
|
- String number = load[i].getString("number");
|
|
|
- JSONObject element = new JSONObject(true);
|
|
|
- element.put("PersonNo", number);
|
|
|
- targets.add(element);
|
|
|
- }
|
|
|
- m.put("targets", targets);//待办所属对象
|
|
|
- }else {
|
|
|
- JSONObject targets = new JSONObject(true);
|
|
|
- targets.put("PersonNo", load[0].getString("number"));
|
|
|
- m.put("targets", targets);//待办所属对象
|
|
|
- }
|
|
|
- return m;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteToDo(MessageContext messageContext, ToDoInfo toDoInfo) {
|
|
|
- log.info("删除待办为已办开始 ctx: " + messageContext.toString() + ",taskId:" + messageContext.getTaskId());
|
|
|
- try {
|
|
|
- List<Long> userIds = toDoInfo.getUserIds();
|
|
|
- if (CollectionUtils.isEmpty(userIds)) {
|
|
|
- log.info("人员为空,推送失败");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- log.info("获取用户开始");
|
|
|
- QFilter qFilter = new QFilter("id", QCP.in, userIds);
|
|
|
- DynamicObject[] load = BusinessDataServiceHelper.load(USER_FORM_ID, "number", qFilter.toArray());
|
|
|
- log.info("获取用户结束:"+load[0].getPkValue());
|
|
|
-
|
|
|
- log.info("获取任务:");
|
|
|
- boolean isExist = QueryServiceHelper.exists("wf_task",toDoInfo.getTaskId());
|
|
|
- if(isExist){
|
|
|
- DynamicObject taskInfo = BusinessDataServiceHelper.loadSingleFromCache(toDoInfo.getTaskId() ,"wf_task");
|
|
|
- log.info("获取任务结束:"+taskInfo.getPkValue());
|
|
|
- JSONObject m = getToDelJson(toDoInfo,load,taskInfo);
|
|
|
- doPostByHttpClient(deleteUrl, m.toString());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("更新待办失败" + e.getMessage());
|
|
|
- log.info(e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取创建审批实例json
|
|
|
- * @return
|
|
|
- */
|
|
|
- public JSONObject getToDelJson(ToDoInfo toDoInfo,DynamicObject[] load, DynamicObject taskInfo){
|
|
|
- JSONObject m = new JSONObject(true);
|
|
|
- m.put("appName","ycq");//待办来源
|
|
|
- m.put("modelName",taskInfo.getString("entityname"));//模块名
|
|
|
- m.put("modelId", toDoInfo.getTaskId());//待办唯一标识
|
|
|
- m.put("optType", 2);//操作类型(1:表示删除待办操作,2:表示删除指定待办所属人操作)
|
|
|
- m.put("param1", null);//关键字
|
|
|
- m.put("param2", null);//关键字
|
|
|
- m.put("key", null);//关键字
|
|
|
- m.put("type", null);//关键字
|
|
|
-
|
|
|
- if (load.length > 1) {
|
|
|
- JSONArray targets = new JSONArray();
|
|
|
- for (int i = 0; i < load.length; i++) {
|
|
|
- String number = load[i].getString("number");
|
|
|
- JSONObject element = new JSONObject(true);
|
|
|
- element.put("PersonNo", number);
|
|
|
- targets.add(element);
|
|
|
- }
|
|
|
- m.put("targets", targets);//待办所属对象
|
|
|
- }else {
|
|
|
- JSONObject targets = new JSONObject(true);
|
|
|
- targets.put("PersonNo", load[0].getString("number"));
|
|
|
- m.put("targets", targets);//待办所属对象
|
|
|
- }
|
|
|
- return m;
|
|
|
- }
|
|
|
-}
|