yingp 5 жил өмнө
parent
commit
c49a3c39f3

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-## UAS对接企业微信
+## UAS在线办公集成
 
 ### 项目结构
 

+ 1 - 0
build.gradle

@@ -25,6 +25,7 @@ subprojects { Project subproject ->
         // dependencies
         ojdbc = 'com.oracle:ojdbc6:11.2.0'
         fastjson = 'com.alibaba:fastjson:1.2.47'
+        threadLocal = 'com.alibaba:transmittable-thread-local:2.2.0'
         
         repoBaseUrl = "http://maven.ubtob.com/artifactory"
         snapshotUrl = "$repoBaseUrl/libs-snapshot-local"

+ 2 - 2
qywx-sdk/src/test/java/com/usoftchina/qywx/sdk/test/BaseTest.java

@@ -23,9 +23,9 @@ public abstract class BaseTest {
         // 通讯录
         agents.add(new Agent("AddressBook", null, "uXuJXVLSjMsvvqPeb8tFDAVDZAphz1PoMcMN4KDuV7g"));
         // 日程
-        agents.add(new Agent("Schedule", null, "hGfE3pCpKAKlzT0KGXeAVsq4W0niqxI1NERl0ztuMKE"));
+        agents.add(new Agent("Schedule", null, "nBfWqPZS8GXNnkBovhtjMl8UCKI5XoaXUuZnz_Oxkao"));
         // 打卡
-        agents.add(new Agent("Checkin", 3010011, "jCtXuCvBUQDSSTt3chYDs0qHhYeBPEdXxGV7TX7rmm8"));
+        agents.add(new Agent("Checkin", 3010011, "UqGEo3694hopQIfsd3fEDVx0b0rscrl5QzNsOUeZ4lU"));
         // 审批
         agents.add(new Agent("Approval", 3010040, "sSwb62-S-bGftHcCVChnxASz8SnqnvobtIU8Q42kT2w"));
 

+ 13 - 1
qywx-sdk/src/test/java/com/usoftchina/qywx/sdk/test/OaSdkTest.java

@@ -2,6 +2,8 @@ package com.usoftchina.qywx.sdk.test;
 
 import com.alibaba.fastjson.JSON;
 import com.usoftchina.qywx.sdk.OaSdk;
+import com.usoftchina.qywx.sdk.dto.GetCheckinDataReq;
+import com.usoftchina.qywx.sdk.dto.GetCheckinDataResp;
 import com.usoftchina.qywx.sdk.dto.GetCheckinOptionReq;
 import com.usoftchina.qywx.sdk.dto.GetCheckinOptionResp;
 import org.junit.Test;
@@ -26,9 +28,19 @@ public class OaSdkTest extends BaseTest {
     @Test
     public void getCheckinOption() {
         List<GetCheckinOptionResp.CheckinOption> options = sdk.getCheckinOption(new GetCheckinOptionReq(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000,
-                Arrays.asList("YingPeng")));
+                Arrays.asList("U0308")));
         if (!CollectionUtils.isEmpty(options)) {
             System.out.println(JSON.toJSONString(options));
         }
     }
+
+    @Test
+    public void getCheckinData() {
+        List<GetCheckinDataResp.CheckinData> dataList = sdk.getCheckinData(new GetCheckinDataReq(
+                GetCheckinDataReq.CheckinType.ALL, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000,
+                System.currentTimeMillis() / 1000, Arrays.asList("U0308")));
+        if (!CollectionUtils.isEmpty(dataList)) {
+            System.out.println(JSON.toJSONString(dataList));
+        }
+    }
 }

+ 1 - 0
uas-office-core/build.gradle

@@ -3,4 +3,5 @@ dependencies {
     compile 'org.springframework.boot:spring-boot-starter-jdbc'
     compile 'org.springframework.boot:spring-boot-starter-data-redis'
     compile "$fastjson"
+    compile "$threadLocal"
 }

+ 2 - 1
uas-office-core/src/main/java/com/usoftchina/uas/office/context/MasterHolder.java

@@ -1,5 +1,6 @@
 package com.usoftchina.uas.office.context;
 
+import com.alibaba.ttl.TransmittableThreadLocal;
 import com.usoftchina.uas.office.entity.Master;
 
 /**
@@ -8,7 +9,7 @@ import com.usoftchina.uas.office.entity.Master;
  */
 public class MasterHolder {
 
-    private static final ThreadLocal<Master> threadLocalMaster = new InheritableThreadLocal<>();
+    private static final ThreadLocal<Master> threadLocalMaster = new TransmittableThreadLocal<>();
 
     /**
      * 获取当前Master

+ 9 - 5
uas-office-core/src/main/java/com/usoftchina/uas/office/jdbc/DataSourceHolder.java

@@ -1,12 +1,15 @@
 package com.usoftchina.uas.office.jdbc;
 
+import com.alibaba.ttl.TransmittableThreadLocal;
+import com.usoftchina.uas.office.context.ContextHolder;
+
 /**
  * @author yingp
  * @date 2019/5/23
  */
 public abstract class DataSourceHolder {
 
-    private static final ThreadLocal<DataSourceBean> threadLocalBean = new InheritableThreadLocal<>();
+    private static final ThreadLocal<DataSourceBean> threadLocalBean = new TransmittableThreadLocal<>();
 
     /**
      * 获取当前数据源
@@ -23,10 +26,11 @@ public abstract class DataSourceHolder {
      * @param bean
      */
     public static void set(DataSourceBean bean) {
-        DataSourceBean old = get();
-        boolean changed = null == old || !old.equals(bean);
-        if (changed) {
-            threadLocalBean.set(bean);
+        threadLocalBean.set(bean);
+        try {
+            ContextHolder.getApplicationContext().getBean(DynamicDataSourceRegister.class).register(bean);
+        } catch (Exception e) {
+            throw new RuntimeException("错误数据连接", e);
         }
     }
 

+ 0 - 1
uas-office-core/src/main/java/com/usoftchina/uas/office/service/AbstractService.java

@@ -1,7 +1,6 @@
 package com.usoftchina.uas.office.service;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.parser.Feature;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DataAccessException;
 import org.springframework.dao.EmptyResultDataAccessException;

+ 18 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/manage/service/QywxSettingService.java

@@ -1,9 +1,13 @@
 package com.usoftchina.uas.office.qywx.manage.service;
 
 import com.usoftchina.uas.office.context.ContextHolder;
+import com.usoftchina.uas.office.event.DataCenterEvent;
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
 import com.usoftchina.uas.office.qywx.manage.entity.QywxSetting;
 import com.usoftchina.uas.office.qywx.manage.event.QywxCorpEvent;
 import com.usoftchina.uas.office.service.AbstractService;
+import org.springframework.context.event.EventListener;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
@@ -45,4 +49,18 @@ public class QywxSettingService extends AbstractService {
             jdbcTemplate.update("update QywxSetting set checkin_time=?", checkinTime);
         }
     }
+
+    @Async
+    @EventListener(DataCenterEvent.class)
+    public void onDataCenterEvent(DataCenterEvent event) throws Exception {
+        try {
+            DataSourceHolder.set(event.getDataCenter());
+            QywxSetting setting = find();
+            if (null != setting && null != setting.getCorpId()) {
+                ContextHolder.getApplicationContext().publishEvent(new QywxCorpEvent(this, setting.getCorpId()));
+            }
+        } finally {
+            DataSourceHolder.clear();
+        }
+    }
 }

+ 1 - 3
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/task/QywxCheckinTask.java

@@ -18,7 +18,6 @@ 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.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.time.LocalDate;
@@ -64,8 +63,7 @@ public class QywxCheckinTask {
     /**
      * 抓取打卡数据
      */
-    @Scheduled(fixedDelay = 300000)
-    @Transactional(rollbackFor = Exception.class)
+    @Scheduled(fixedDelay = 300000, initialDelay = 30000)
     public void pullCheckinData() {
         if (!oaSdk.isAgentEnabled(OaSdk.CHECKIN_AGENT_CODE)) {
             return;

+ 2 - 2
uas-office-server/src/main/java/com/usoftchina/uas/office/UasQywxIntegration.java → uas-office-server/src/main/java/com/usoftchina/uas/office/UasOfficeServer.java

@@ -14,8 +14,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @EnableAsync
 @EnableScheduling
 @EnableTransactionManagement
-public class UasQywxIntegration {
+public class UasOfficeServer {
     public static void main(String[] args) {
-        SpringApplication.run(UasQywxIntegration.class, args);
+        SpringApplication.run(UasOfficeServer.class, args);
     }
 }

+ 1 - 1
uas-office-server/src/main/resources/application.yaml

@@ -33,4 +33,4 @@ spring:
 logging:
   path: ${user.home}/.qywx/logs/
   level:
-    com.usoftchina.uas.qywx: debug
+    com.usoftchina.uas.office: debug

+ 2 - 2
uas-office-server/src/main/resources/static/agent.html

@@ -69,8 +69,8 @@
                     <div class="form-group">
                         <label for="readonlyInput">是否只读</label>
                         <select class="form-control" id="readonlyInput" name="readonly">
-                            <option value="true">是</option>
-                            <option value="false">否</option>
+                            <option value="1">是</option>
+                            <option value="0">否</option>
                         </select>
                     </div>
                 </form>

+ 1 - 1
uas-office-server/src/main/resources/static/js/agent.js

@@ -19,7 +19,7 @@ $(document).ready(function () {
                                 $('#descriptionInput').val(agent.description);
                                 $('#agentIdInput').val(agent.agentId);
                                 $('#secretInput').val(agent.secret);
-                                $('#readonlyInput').val(String(agent.readonly));
+                                $('#readonlyInput').val(agent.readonly);
                             });
                             $('.btn-delete').click(function(){
                                 var index = $(this).data('index'),