Browse Source

Merge branch 'master' of ssh://10.10.100.21/source/uas-office-integration

RaoMeng 6 years ago
parent
commit
cda0b3876d

+ 11 - 0
uas-office-core/src/main/java/com/usoftchina/uas/office/dto/UasEvent.java

@@ -51,6 +51,17 @@ public class UasEvent {
         this.timestamp = timestamp;
         this.timestamp = timestamp;
     }
     }
 
 
+    public UasEvent() {
+    }
+
+    public UasEvent(String operation, String caller, Object key, String master) {
+        this.operation = operation;
+        this.caller = caller;
+        this.key = key;
+        this.master = master;
+        this.timestamp = System.currentTimeMillis();
+    }
+
     @Override
     @Override
     public String toString() {
     public String toString() {
         return "UasEvent{" +
         return "UasEvent{" +

+ 1 - 1
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/listener/UasProcessListener.java

@@ -73,7 +73,7 @@ public class UasProcessListener {
         }
         }
         DataCenter dataCenter = DataCenter.INSTANCE;
         DataCenter dataCenter = DataCenter.INSTANCE;
         String title = process.getJp_launchername() + "的" + process.getJp_name();
         String title = process.getJp_launchername() + "的" + process.getJp_name();
-        String description = "单据编号:" + process.getJp_codevalue();
+        String description = process.getJp_launchername() + "的" + process.getJp_name()+ "  \n单据编号:" + process.getJp_codevalue();
         try {
         try {
             // 往uas应用发送
             // 往uas应用发送
             DingTalkAgent agent = getUasAgent();
             DingTalkAgent agent = getUasAgent();

+ 75 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/entity/UApprovalMsg.java

@@ -0,0 +1,75 @@
+package com.usoftchina.uas.office.qywx.entity;
+
+
+/**
+ * @author wuyx
+ * @date 2020/2/16
+ */
+public class UApprovalMsg {
+    private Integer id_;
+    private String type_;
+    private String title_;
+    private String msg_;
+    private String ems_;
+    private String url_;
+
+    public Integer getId_() {
+        return id_;
+    }
+
+    public void setId_(Integer id_) {
+        this.id_ = id_;
+    }
+
+    public String getType_() {
+        return type_;
+    }
+
+    public void setType_(String type_) {
+        this.type_ = type_;
+    }
+
+    public String getTitle_() {
+        return title_;
+    }
+
+    public void setTitle_(String title_) {
+        this.title_ = title_;
+    }
+
+    public String getMsg_() {
+        return msg_;
+    }
+
+    public void setMsg_(String msg_) {
+        this.msg_ = msg_;
+    }
+
+    public String getEms_() {
+        return ems_;
+    }
+
+    public void setEms_(String ems_) {
+        this.ems_ = ems_;
+    }
+
+    public String getUrl_() {
+        return url_;
+    }
+
+    public void setUrl_(String url_) {
+        this.url_ = url_;
+    }
+
+    @Override
+    public String toString() {
+        return "UApprovalMsg{" +
+                "id_='" + id_ + '\'' +
+                ", type_='" + type_ + '\'' +
+                ", title_='" + title_ + '\'' +
+                ", msg_='" + msg_ + '\'' +
+                ", ems_='" + ems_ + '\'' +
+                ", url_='" + url_ + '\'' +
+                '}';
+    }
+}

+ 60 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/listener/UasMsgListener.java

@@ -0,0 +1,60 @@
+package com.usoftchina.uas.office.qywx.listener;
+
+import com.usoftchina.qywx.sdk.MessageSdk;
+import com.usoftchina.qywx.sdk.dto.SendMessageReq;
+import com.usoftchina.uas.office.dto.UasEvent;
+import com.usoftchina.uas.office.listener.UasEventListener;
+import com.usoftchina.uas.office.qywx.manage.service.QywxAgentService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author yingp
+ * @date 2020/2/16
+ */
+@Component
+public class UasMsgListener {
+
+    @Autowired
+    private MessageSdk messageSdk;
+    @Autowired
+    private QywxAgentService agentService;
+    private final Logger logger = LoggerFactory.getLogger(UasMsgListener.class);
+
+    /**
+     * uas催办审批任务,发送消息到企业微信
+     *
+     * @param event
+     */
+    @UasEventListener(caller = "MarkDownMsg", operation = "SENDUAPPROVALMSG")
+    public void onProcessURGEDDEAL(UasEvent event) {
+        if (!messageSdk.isAgentEnabled("Uas")) {
+            return;
+        }
+        if (event.getKey() instanceof List) {
+            List<Map<String,Object>> msgList = (List<Map<String,Object>>) event.getKey();
+            msgList.forEach(msg -> {
+                sendUasMessage(event, msg);
+            });
+        } else {
+            sendUasMessage(event, (Map<String,Object>) event.getKey());
+        }
+    }
+    private void sendUasMessage(UasEvent event, Map<String,Object> msg) {
+        try {
+            String msgConten = msg.get("msgConten") == null ? "":String.valueOf(msg.get("msgConten"));
+            String em = msg.get("em") == null ? "":String.valueOf(msg.get("em"));
+            if(em.length()>0){
+                messageSdk.send("Uas", new SendMessageReq().markdown(msgConten).toUser(em.split(",")));
+                logger.info("send uas message sucess {}", msg);
+            }
+        }catch (Exception e){
+            logger.error("send uas message error", e);
+        }
+    }
+}

+ 33 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/manage/controller/QywxAddrBookController.java

@@ -2,8 +2,10 @@ package com.usoftchina.uas.office.qywx.manage.controller;
 
 
 import com.usoftchina.qywx.sdk.AddrBookSdk;
 import com.usoftchina.qywx.sdk.AddrBookSdk;
 import com.usoftchina.uas.office.dto.Result;
 import com.usoftchina.uas.office.dto.Result;
+import com.usoftchina.uas.office.dto.UasEvent;
 import com.usoftchina.uas.office.entity.DataCenter;
 import com.usoftchina.uas.office.entity.DataCenter;
 import com.usoftchina.uas.office.jdbc.DataSourceHolder;
 import com.usoftchina.uas.office.jdbc.DataSourceHolder;
+import com.usoftchina.uas.office.listener.UasEventListenerFactory;
 import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
 import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
 import com.usoftchina.uas.office.qywx.service.UasOrgService;
 import com.usoftchina.uas.office.qywx.service.UasOrgService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +31,9 @@ public class QywxAddrBookController {
     @Autowired
     @Autowired
     private AddrBookSdk addrBookSdk;
     private AddrBookSdk addrBookSdk;
 
 
+    @Autowired
+    private UasEventListenerFactory eventListenerFactory;
+
     @PostMapping(path = "/addrbook/sync")
     @PostMapping(path = "/addrbook/sync")
     public Result syncAll() {
     public Result syncAll() {
         DataCenter dataCenter = DataCenter.INSTANCE;
         DataCenter dataCenter = DataCenter.INSTANCE;
@@ -58,4 +63,32 @@ public class QywxAddrBookController {
     public Result getDepartmentList() {
     public Result getDepartmentList() {
         return Result.success(addrBookSdk.getDepartmentList());
         return Result.success(addrBookSdk.getDepartmentList());
     }
     }
+
+    /**
+     * 同步单个用户
+     *
+     * @param id
+     * @return
+     */
+    @RequestMapping(path = "/addrbook/user/sync")
+    public Result syncUser(Integer id) {
+        UasEvent event = new UasEvent("AUDIT", "Employeemanager", id,
+                DataCenter.INSTANCE.getUsername());
+        eventListenerFactory.invokeListeners(event);
+        return Result.success();
+    }
+
+    /**
+     * 同步单个组织
+     *
+     * @param id
+     * @return
+     */
+    @RequestMapping(path = "/addrbook/org/sync")
+    public Result syncOrg(Integer id) {
+        UasEvent event = new UasEvent("UPDATE", "HrOrg", id,
+                DataCenter.INSTANCE.getUsername());
+        eventListenerFactory.invokeListeners(event);
+        return Result.success();
+    }
 }
 }

+ 25 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/service/UasUApprovalMsgService.java

@@ -0,0 +1,25 @@
+package com.usoftchina.uas.office.qywx.service;
+
+import com.usoftchina.uas.office.qywx.entity.UApprovalMsg;
+import com.usoftchina.uas.office.service.AbstractService;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * @author wuyx
+ * @date 2020/5/11
+ */
+@Service
+public class UasUApprovalMsgService extends AbstractService {
+    public List<UApprovalMsg> getAllMsg() {
+        return queryForBeanList("select * from UAPPROVALMSG where EMS_ IS NOT NULL AND TYPE_ IS NOT NULL", UApprovalMsg.class);
+    }
+    public void delMsg(){
+        jdbcTemplate.execute("delete UAPPROVALMSG where ID_ IN (SELECT ID_ FROM UAPPROVALMSG_HIS) ");
+    }
+    public void recodMsg(Integer id_,String status,String reason){
+        jdbcTemplate.execute("INSERT INTO UAPPROVALMSG_HIS (ID_, TYPE_, TITLE_, MSG_, EMS_, URL_,PUSHDATE_,PUSHSTATUS_,FAILREASON_) " +
+                " SELECT TT.*,SYSDATE,'"+status+"','"+reason+"' FROM UAPPROVALMSG TT WHERE TT.ID_ = "+id_);
+    }
+}

+ 77 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/task/QywxPushMsgTask.java

@@ -0,0 +1,77 @@
+package com.usoftchina.uas.office.qywx.task;
+
+import com.usoftchina.qywx.sdk.MessageSdk;
+import com.usoftchina.qywx.sdk.dto.SendMessageReq;
+import com.usoftchina.uas.office.entity.DataCenter;
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
+import com.usoftchina.uas.office.qywx.entity.UApprovalMsg;
+import com.usoftchina.uas.office.qywx.service.UasUApprovalMsgService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+
+/**
+ * @author wuyx
+ * @date 2020/5/11
+ */
+@Component
+public class QywxPushMsgTask {
+
+    @Autowired
+    private MessageSdk messageSdk;
+
+    @Autowired
+    private UasUApprovalMsgService uasUApprovalMsgService;
+
+    private final Logger logger = LoggerFactory.getLogger(QywxPushMsgTask.class);
+
+    /**
+     *U审批自定义消息推送
+     */
+    @Scheduled(cron="0 0/2 * * * ?")
+    public void pushUapprovalMsg() {
+        if (!messageSdk.isAgentEnabled("Uas")) {
+            return;
+        }
+        DataCenter dataCenter = DataCenter.INSTANCE;
+        if (null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
+            try {
+                DataSourceHolder.set(dataCenter);
+                try {
+                    List<UApprovalMsg> uMsgList = uasUApprovalMsgService.getAllMsg();
+                    for(UApprovalMsg uMsg : uMsgList){
+                        SendMessageReq sendMsg = new SendMessageReq();
+                        if(uMsg.getType_().equals("MARKDOWN")){
+                            sendMsg.markdown(uMsg.getMsg_());
+                        }else if(uMsg.getType_().equals("TEXT")){
+                            sendMsg.text(uMsg.getMsg_());
+                        }else if(uMsg.getType_().equals("TEXTCARD")){
+                            sendMsg.textCard(uMsg.getTitle_(),uMsg.getMsg_(),uMsg.getUrl_(),"查看详情");
+                        }else {
+                            continue;
+                        }
+                        sendMsg.toUser(uMsg.getEms_().split(","));
+                        try {
+                            messageSdk.send("Uas", sendMsg);
+                            uasUApprovalMsgService.recodMsg(uMsg.getId_(),"SUCESS","");
+                            logger.info("send uas custom message sucess {}", uMsg);
+                        }catch (Exception e){
+                            uasUApprovalMsgService.recodMsg(uMsg.getId_(),"FAIL",(e.getMessage().length() >= 1000 ? e.getMessage().substring(0,1000) : e.getMessage()));
+                            throw e;
+                        }
+                    }
+                }catch (Exception e){
+                    logger.error("send uas custom message error", e);
+                }
+            } finally {
+                uasUApprovalMsgService.delMsg();
+                DataSourceHolder.clear();
+            }
+        }
+    }
+}