Commit 8dae4cb38a18dd1c3b28676842bf5fa1aa8f989e

Authored by yiming
1 parent 1244cf37

首末站同步定时器

bsthLineProfiles/src/main/java/com/ruoyi/project/monitor/job/task/RyTask.java
@@ -12,7 +12,9 @@ import cn.hutool.http.HttpUtil; @@ -12,7 +12,9 @@ import cn.hutool.http.HttpUtil;
12 import com.alibaba.fastjson.JSONObject; 12 import com.alibaba.fastjson.JSONObject;
13 import com.ruoyi.common.utils.security.ShiroUtils; 13 import com.ruoyi.common.utils.security.ShiroUtils;
14 import com.ruoyi.project.system.dept.service.DeptServiceImpl; 14 import com.ruoyi.project.system.dept.service.DeptServiceImpl;
  15 +import com.ruoyi.project.system.line.domain.BsthSite;
15 import com.ruoyi.project.system.line.domain.BsthStation; 16 import com.ruoyi.project.system.line.domain.BsthStation;
  17 +import com.ruoyi.project.system.line.mapper.BsthSiteMapper;
16 import com.ruoyi.project.system.line.mapper.BsthStationMapper; 18 import com.ruoyi.project.system.line.mapper.BsthStationMapper;
17 import com.ruoyi.project.system.user.domain.User; 19 import com.ruoyi.project.system.user.domain.User;
18 import org.apache.shiro.util.ThreadContext; 20 import org.apache.shiro.util.ThreadContext;
@@ -44,6 +46,9 @@ public class RyTask { @@ -44,6 +46,9 @@ public class RyTask {
44 @Autowired 46 @Autowired
45 BsthStationMapper bsthStationMapper; 47 BsthStationMapper bsthStationMapper;
46 48
  49 + @Autowired
  50 + BsthSiteMapper bsthSiteMapper;
  51 +
47 public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { 52 public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
48 System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); 53 System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
49 } 54 }
@@ -157,5 +162,28 @@ public class RyTask { @@ -157,5 +162,28 @@ public class RyTask {
157 162
158 } 163 }
159 } 164 }
  165 + public void updateSite(){
  166 + List<BsthSite> bsthSites=bsthSiteMapper.selectBsthSite();
  167 + Map<String,List<BsthSite>> m=bsthSites.stream().collect(Collectors.groupingBy(v->(String.valueOf(v.getId()))));
  168 + String url="http://180.166.5.82:19006/site/Site_list";
  169 + JSONArray jsonArray=JSONObject.parseArray(HttpUtil.post(url,new HashMap<>()));
  170 + for (Object o : jsonArray) {
  171 + BsthSite b=JSONObject.parseObject(o.toString(), BsthSite.class);
  172 + List<BsthSite> bsthSiteList=m.get(String.valueOf(b.getId()));
  173 + if(bsthSiteList==null){
  174 + bsthSiteMapper.insertBsthSite(b);
  175 + }else {
  176 + BsthSite bsthSite=bsthSiteList.get(0);
  177 + if(!b.equals(bsthSite)){
  178 + bsthSiteMapper.updateBsthSite(b);
  179 + }
  180 + }
  181 + }
  182 + }
  183 +
  184 + public static void main(String[] args) {
  185 + RyTask ryTask=new RyTask();
  186 + ryTask.updateSite();
  187 + }
160 188
161 } 189 }
bsthLineProfiles/src/main/java/com/ruoyi/project/system/line/domain/BsthSite.java 0 → 100644
  1 +package com.ruoyi.project.system.line.domain;
  2 +
  3 +
  4 +import java.util.Objects;
  5 +
  6 +public class BsthSite
  7 +{
  8 + private static final long serialVersionUID = 1L;
  9 +
  10 +
  11 + private long id;
  12 +
  13 + private String ddname;
  14 +
  15 + private String name;
  16 +
  17 + public long getId() {
  18 + return id;
  19 + }
  20 +
  21 + public void setId(long id) {
  22 + this.id = id;
  23 + }
  24 +
  25 + public String getDdname() {
  26 + return ddname;
  27 + }
  28 +
  29 + public void setDdname(String ddname) {
  30 + this.ddname = ddname;
  31 + }
  32 +
  33 + public String getName() {
  34 + return name;
  35 + }
  36 +
  37 + public void setName(String name) {
  38 + this.name = name;
  39 + }
  40 +
  41 + @Override
  42 + public boolean equals(Object o) {
  43 + if (this == o) return true;
  44 + if (o == null || getClass() != o.getClass()) return false;
  45 + BsthSite bsthSite = (BsthSite) o;
  46 + return Objects.equals(id, bsthSite.id) && Objects.equals(ddname, bsthSite.ddname) && Objects.equals(name, bsthSite.name);
  47 + }
  48 +
  49 + @Override
  50 + public int hashCode() {
  51 + return Objects.hash(id, ddname, name);
  52 + }
  53 +
  54 + @Override
  55 + public String toString() {
  56 + return "BsthSite{" +
  57 + "id='" + id + '\'' +
  58 + ", ddname='" + ddname + '\'' +
  59 + ", name='" + name + '\'' +
  60 + '}';
  61 + }
  62 +}
bsthLineProfiles/src/main/java/com/ruoyi/project/system/line/domain/BsthTLineKFK.java
@@ -190,6 +190,9 @@ public class BsthTLineKFK @@ -190,6 +190,9 @@ public class BsthTLineKFK
190 /** 类型 */ 190 /** 类型 */
191 private String operationType; 191 private String operationType;
192 192
  193 + /** 线路编码 */
  194 + private String lineCode;
  195 +
193 196
194 public BsthTLineKFK(){ 197 public BsthTLineKFK(){
195 198
@@ -670,4 +673,12 @@ public class BsthTLineKFK @@ -670,4 +673,12 @@ public class BsthTLineKFK
670 public void setId(Long id) { 673 public void setId(Long id) {
671 this.id = id; 674 this.id = id;
672 } 675 }
  676 +
  677 + public String getLineCode() {
  678 + return lineCode;
  679 + }
  680 +
  681 + public void setLineCode(String lineCode) {
  682 + this.lineCode = lineCode;
  683 + }
673 } 684 }
bsthLineProfiles/src/main/java/com/ruoyi/project/system/line/mapper/BsthSiteMapper.java 0 → 100644
  1 +package com.ruoyi.project.system.line.mapper;
  2 +
  3 +
  4 +import com.ruoyi.project.system.line.domain.BsthSite;
  5 +import org.apache.ibatis.annotations.Mapper;
  6 +import java.util.List;
  7 +
  8 +@Mapper
  9 +public interface BsthSiteMapper
  10 +{
  11 +
  12 +
  13 + List<BsthSite> selectBsthSite();
  14 +
  15 + void updateBsthSite(BsthSite bsthSite);
  16 +
  17 + void insertBsthSite(BsthSite bsthSite);
  18 +
  19 +}
bsthLineProfiles/src/main/resources/application.yml
@@ -100,7 +100,7 @@ spring: @@ -100,7 +100,7 @@ spring:
100 # 令牌密钥 100 # 令牌密钥
101 secret: abcdefghijklmnopqrstuvwxyz 101 secret: abcdefghijklmnopqrstuvwxyz
102 # 令牌有效期(默认30分钟) 102 # 令牌有效期(默认30分钟)
103 - expireTime: 30 103 + expireTime: 360
104 104
105 kafka: 105 kafka:
106 bootstrap-servers: 47.106.82.232:9092 106 bootstrap-servers: 47.106.82.232:9092
@@ -157,7 +157,7 @@ shiro: @@ -157,7 +157,7 @@ shiro:
157 cipherKey: zSyK5Kp6PZAAjlT+eeNMlg== 157 cipherKey: zSyK5Kp6PZAAjlT+eeNMlg==
158 session: 158 session:
159 # Session超时时间,-1代表永不过期(默认30分钟) 159 # Session超时时间,-1代表永不过期(默认30分钟)
160 - expireTime: 30 160 + expireTime: 360
161 # 同步session到数据库的周期(默认1分钟) 161 # 同步session到数据库的周期(默认1分钟)
162 dbSyncPeriod: 1 162 dbSyncPeriod: 1
163 # 相隔多久检查一次session的有效性,默认就是10分钟 163 # 相隔多久检查一次session的有效性,默认就是10分钟
bsthLineProfiles/src/main/resources/mybatis/mybatis/system/BsthSiteMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper
  3 +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 +"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.ruoyi.project.system.line.mapper.BsthSiteMapper">
  6 +
  7 + <select id="selectBsthSite" resultType="com.ruoyi.project.system.line.domain.BsthSite">
  8 + select id,ddname,name from bsth_t_site
  9 + </select>
  10 +
  11 + <update id="updateBsthSite" parameterType="com.ruoyi.project.system.line.domain.BsthSite">
  12 + update bsth_t_site
  13 + <trim prefix="SET" suffixOverrides=",">
  14 + <if test="ddname != null">ddname = #{ddname},</if>
  15 + <if test="name != null">name = #{name},</if>
  16 + </trim>
  17 + where id = #{id}
  18 + </update>
  19 +
  20 + <insert id="insertBsthSite" parameterType="com.ruoyi.project.system.line.domain.BsthSite">
  21 + insert into bsth_t_site
  22 + <trim prefix="(" suffix=")" suffixOverrides=",">
  23 + <if test="id != null and id != ''">id,</if>
  24 + <if test="ddname != null and ddname != ''">ddname,</if>
  25 + <if test="name != null and name != ''">name,</if>
  26 + </trim>
  27 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  28 + <if test="id != null and id != ''">#{id},</if>
  29 + <if test="ddname != null and ddname != ''">#{ddname},</if>
  30 + <if test="name != null and name != ''">#{name},</if>
  31 + </trim>
  32 + </insert>
  33 +
  34 +</mapper>
0 \ No newline at end of file 35 \ No newline at end of file