|
|
@@ -0,0 +1,122 @@
|
|
|
+package com.usoftchina.uas.office.dingtalk.task;
|
|
|
+
|
|
|
+import com.usoftchina.dingtalk.sdk.MessageSdk;
|
|
|
+import com.usoftchina.dingtalk.sdk.dto.SendMessageReq;
|
|
|
+import com.usoftchina.dingtalk.sdk.util.UrlUtils;
|
|
|
+import com.usoftchina.uas.office.dingtalk.entity.Employee;
|
|
|
+import com.usoftchina.uas.office.dingtalk.manage.entity.DingTalkAgent;
|
|
|
+import com.usoftchina.uas.office.dingtalk.manage.service.DingTalkAgentService;
|
|
|
+import com.usoftchina.uas.office.dingtalk.service.UasEmployeeService;
|
|
|
+import com.usoftchina.uas.office.dingtalk.service.UasSubsService;
|
|
|
+import com.usoftchina.uas.office.entity.DataCenter;
|
|
|
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
|
|
|
+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 org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wuyx
|
|
|
+ * @date 2024/7/03
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class DingTalkSubsTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageSdk messageSdk;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasSubsService uasSubsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasEmployeeService uasEmployeeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DingTalkAgentService agentService;
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(DingTalkSubsTask.class);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每日订阅提醒推送
|
|
|
+ */
|
|
|
+ @Scheduled(cron="0 0 19 * * ? ")
|
|
|
+// @Scheduled(fixedDelay = 180000, initialDelay = 10000)
|
|
|
+ public void pushSubsData() {
|
|
|
+ DataCenter dataCenter = DataCenter.INSTANCE;
|
|
|
+ if (null != dataCenter.getUrl()) {
|
|
|
+ try {
|
|
|
+ DataSourceHolder.set(dataCenter);
|
|
|
+ try {
|
|
|
+ boolean pushFlag = uasSubsService.pushSubsDataEnable();
|
|
|
+ System.out.println("pushFlag:"+pushFlag);
|
|
|
+ if(!pushFlag){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ //获取要推送人员列表
|
|
|
+ List<Employee> emList = new ArrayList<>();
|
|
|
+// emList = uasEmployeeService.getAll();
|
|
|
+ Employee emp = uasEmployeeService.getByCode("TEST");
|
|
|
+ if(emp!=null){
|
|
|
+ emList.add(emp);
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(emList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DingTalkAgent agent = getUasAgent();
|
|
|
+ for(Employee employee : emList){
|
|
|
+ try {
|
|
|
+ String title = "您有新的订阅信息";
|
|
|
+ String description ="您有新的订阅信息,共:(%s)条。";
|
|
|
+ String agentUrl = agent.getOuterUrl();
|
|
|
+ String process = agentUrl.substring(agentUrl.indexOf("/",10)+1,agentUrl.indexOf("/",agentUrl.indexOf("/",10)+1));
|
|
|
+ //获取待推送的订阅信息
|
|
|
+ List<Map<String,Object>> remindList =uasSubsService.getSubs_instance(employee.getEm_id());
|
|
|
+ if(remindList.size() > 0){
|
|
|
+ try {
|
|
|
+ // 往uas应用发送
|
|
|
+ description = String.format(description,remindList.size());
|
|
|
+ List<SendMessageReq.ActionUrlList> urlList = new ArrayList<>();
|
|
|
+ for (int i = 0; i <remindList.size(); i++) {
|
|
|
+ Map<String,Object> remindRecor = remindList.get(i);
|
|
|
+ if(i > 2){
|
|
|
+ break;
|
|
|
+ }//https://erp.yitoa.com:8888/ERP/uasMobile/#/ERP/uasMobile/subscribeChart/660372/20665/85487
|
|
|
+ String msgUrl=UrlUtils.generateAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "Uas", agentUrl.substring(0,agentUrl.indexOf("#")+2),
|
|
|
+ dataCenter.getOuterUrl() + "authorize",process+"/uasMobile/subscribeChart/"+remindRecor.get("ID_")+"/"+remindRecor.get("NUM_ID_")
|
|
|
+ +"/"+remindRecor.get("INSTANCE_ID_") );
|
|
|
+ urlList.add(new SendMessageReq.ActionUrlList(remindRecor.get("TITLE_").toString(),msgUrl));
|
|
|
+ }
|
|
|
+ if(remindList.size() > 3){//更多 https://erp.yitoa.com:8888/ERP/uasMobile/#/ERP/uasMobile/subscribeList
|
|
|
+ String moreUrl = UrlUtils.generateAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "Uas", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "authorize", process+"/uasMobile/subscribeList");
|
|
|
+ urlList.add(new SendMessageReq.ActionUrlList("更多...",moreUrl));
|
|
|
+ }
|
|
|
+ messageSdk.send("Uas", new SendMessageReq()
|
|
|
+ .actionCardWithMultiUrl(title, description, true,urlList)
|
|
|
+ .toUser(employee.getEm_ding()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("send process message error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("send subs remind error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ DataSourceHolder.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public DingTalkAgent getUasAgent() {
|
|
|
+ return agentService.findByCode("Uas");
|
|
|
+ }
|
|
|
+}
|