|
|
@@ -0,0 +1,105 @@
|
|
|
+package com.usoftchina.uas.office.qywx.task;
|
|
|
+
|
|
|
+import com.usoftchina.qywx.sdk.MessageSdk;
|
|
|
+import com.usoftchina.qywx.sdk.dto.SendMessageReq;
|
|
|
+import com.usoftchina.qywx.sdk.util.UrlUtils;
|
|
|
+import com.usoftchina.uas.office.entity.DataCenter;
|
|
|
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
|
|
|
+import com.usoftchina.uas.office.qywx.entity.Employee;
|
|
|
+import com.usoftchina.uas.office.qywx.manage.entity.QywxAgent;
|
|
|
+import com.usoftchina.uas.office.qywx.manage.service.QywxAgentService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasJProcessService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasSubsService;
|
|
|
+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.net.URLEncoder;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zhouy
|
|
|
+ * @date 2022/7/20
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class QywxSubsTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageSdk messageSdk;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasSubsService uasSubsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasEmployeeService uasEmployeeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QywxAgentService agentService;
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(QywxSubsTask.class);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每日订阅提醒推送
|
|
|
+ */
|
|
|
+ @Scheduled(cron="0 1/1 * * * ? ")
|
|
|
+ public void pullCheckinData() {
|
|
|
+ if (!messageSdk.isAgentEnabled("UasMobile")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DataCenter dataCenter = DataCenter.INSTANCE;
|
|
|
+ if (null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
|
|
|
+ try {
|
|
|
+ DataSourceHolder.set(dataCenter);
|
|
|
+ //获取要推送人员列表
|
|
|
+ List<Employee> emList = uasEmployeeService.getAll();
|
|
|
+ String msgUrl = "";
|
|
|
+ for(Employee em : emList){
|
|
|
+ if(em.getEm_id() !=217){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ QywxAgent agent = agentService.findByCode("UasMobile");
|
|
|
+ //获取待推送的订阅信息
|
|
|
+ List<Map<String,Object>> remindList =uasSubsService.getSubs_instance(em.getEm_id());
|
|
|
+ String process= dataCenter.getOuterUrl().substring(dataCenter.getOuterUrl().lastIndexOf("/")+1);
|
|
|
+ if(remindList.size() > 0){
|
|
|
+ StringBuffer content = new StringBuffer();
|
|
|
+ content.append("**您有<font color=blue>"+remindList.get(0).get("COUNTS")+"</font>个订阅信息**\n" );
|
|
|
+ for (Map<String,Object> remind: remindList) {
|
|
|
+ /* String paramsStr = "{\"numId\":\"" + remind.get("NUM_ID_") + "\",\"mainId\":" + remind.get("INSTANCE_ID_") +"\",\"insId\":" + remind.get("ID_") +"\",\"title\":" + remind.get("TITLE_") + ",\"baseUrl\":\"" + URLEncoder.encode(agent.getOuterUrl(), "utf-8") + "\"}";
|
|
|
+ String msgUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "Uas", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize", "uas/approval/" + URLEncoder.encode(paramsStr, "utf-8"));
|
|
|
+ content.append("> 【停留").append(remind.get("PASSTIME")).append("天】\n ")
|
|
|
+ .append(remind.get("JP_LAUNCHERNAME")).append("的[").append(remind.get("JP_NAME")).append("]("+msgUrl+")\n");*/
|
|
|
+ //root地址 /ID_/NUM_ID_/INSTANCE_ID_
|
|
|
+
|
|
|
+ }
|
|
|
+ for(int i=0; i<remindList.size(); i++){
|
|
|
+ if(i<2){
|
|
|
+ msgUrl=UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "UasMobile", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize","uasMobile/#/"+process+"/uasMobile/subscribeChart/"+remindList.get(i).get("ID_")+"/"+remindList.get(i).get("NUM_ID_")
|
|
|
+ +"/"+remindList.get(i).get("INSTANCE_ID_") );
|
|
|
+ content.append("> [").append(remindList.get(i).get("TITLE_")).append("]("+msgUrl+")\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(remindList.size()>2){
|
|
|
+ String moreUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "UasMobile", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize", "uasMobile/#/"+process+"/uasMobile/subscribeList");
|
|
|
+ content.append("[更多...](").append(moreUrl).append(")");
|
|
|
+ }
|
|
|
+ messageSdk.send("UasMobile", new SendMessageReq().markdown(content.toString()).toUser(em.getEm_qywx()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("send subs remind error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ DataSourceHolder.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|