wangmiaomiao 1 ano atrás
pai
commit
e355d15ad7

+ 13 - 4
slibra-quartz/src/main/java/com/slibra/quartz/task/RyTask.java

@@ -11,6 +11,7 @@ import com.slibra.business.mapper.TXinyiRobotMapper;
 import com.slibra.common.enums.DataSourceType;
 import com.slibra.common.utils.DateUtils;
 import com.slibra.framework.datasource.DynamicDataSourceContextHolder;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import com.slibra.common.utils.StringUtils;
@@ -21,6 +22,7 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 定时任务调度测试
@@ -28,6 +30,7 @@ import java.util.*;
  * 
  */
 @Component("ryTask")
+@Slf4j
 public class RyTask
 {
     public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
@@ -274,13 +277,19 @@ public class RyTask
      * 定时从sqlserver获取数据
      */
     public void sqlserverData(){
-
+        //主库获取上次最新的同步日期
+        String lastTime = this.xinyiRobotMapper.selectLastTime();
         //从
         DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
-        List<TXinyiRobot> tXinyiRobots = xinyiRobotMapper.selectTXinyiRobotList(null);
+        List<TXinyiRobot> tXinyiRobots = xinyiRobotMapper.selectTXinyiRobotListByTime(lastTime);
         DynamicDataSourceContextHolder.clearDataSourceType();
-        System.out.println(JSON.toJSONString(tXinyiRobots));
-        System.out.println("-------------");
+        try {
+            TimeUnit.SECONDS.sleep(3);
+        } catch (InterruptedException e) {
+            log.error(e.getMessage());
+        }
+//        System.out.println(JSON.toJSONString(tXinyiRobots));
+//        System.out.println("-------------");
         //主
         if(!CollectionUtils.isEmpty(tXinyiRobots)){
             for (TXinyiRobot tXinyiRobot : tXinyiRobots) {

+ 4 - 0
slibra-system/src/main/java/com/slibra/business/mapper/TXinyiRobotMapper.java

@@ -58,4 +58,8 @@ public interface TXinyiRobotMapper
      * @return 结果
      */
     public int deleteTXinyiRobotByIDs(Long[] IDs);
+
+    String selectLastTime();
+
+    List<TXinyiRobot> selectTXinyiRobotListByTime(String lastTime);
 }

+ 9 - 0
slibra-system/src/main/resources/mapper/business/TXinyiRobotMapper.xml

@@ -184,4 +184,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{ID}
         </foreach>
     </delete>
+
+    <select id="selectLastTime" resultType="string">
+        SELECT CREATED_TIME from t_xinyi_robot ORDER BY ID desc LIMIT 1
+    </select>
+
+    <select id="selectTXinyiRobotListByTime" parameterType="string" resultMap="TXinyiRobotResult">
+        <include refid="selectTXinyiRobotVo"/> where 1 = 1
+        <if test="lastTime != null  and lastTime != ''"> and CONVERT ( datetime, LTRIM( RTRIM( V_DATE ) ) + ' ' + LTRIM( RTRIM( V_TIME ) ) ) > = #{lastTime}</if>
+    </select>
 </mapper>