|
|
@@ -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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|