Commit dcb2976aeb07ab8231816ad3772878213d32a1b0

Authored by 王通
1 parent 1752cdcb

1.

src/main/java/com/bsth/server_rs/base_info/car/Car.java
@@ -69,6 +69,8 @@ public class Car implements Serializable { @@ -69,6 +69,8 @@ public class Car implements Serializable {
69 69
70 private Date updateDate; 70 private Date updateDate;
71 71
  72 + private String sim;
  73 +
72 public String getNbbm() { 74 public String getNbbm() {
73 return nbbm; 75 return nbbm;
74 } 76 }
@@ -188,4 +190,12 @@ public class Car implements Serializable { @@ -188,4 +190,12 @@ public class Car implements Serializable {
188 public void setUpdateDate(Date updateDate) { 190 public void setUpdateDate(Date updateDate) {
189 this.updateDate = updateDate; 191 this.updateDate = updateDate;
190 } 192 }
  193 +
  194 + public String getSim() {
  195 + return sim;
  196 + }
  197 +
  198 + public void setSim(String sim) {
  199 + this.sim = sim;
  200 + }
191 } 201 }
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarRefreshThread.java
1 package com.bsth.server_rs.base_info.car.buffer; 1 package com.bsth.server_rs.base_info.car.buffer;
2 2
3 import com.bsth.server_rs.base_info.car.Car; 3 import com.bsth.server_rs.base_info.car.Car;
  4 +import com.bsth.util.DBUtils_MS;
4 import org.slf4j.Logger; 5 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,11 +32,18 @@ public class CarRefreshThread extends Thread{ @@ -31,11 +32,18 @@ public class CarRefreshThread extends Thread{
31 32
32 List<Car> list = jdbcTemplate.query("SELECT DISTINCT t1.*,t2.line_code,t2.name as line_name FROM(SELECT c.inside_code as nbbm,c.business_code as company_code,c.branche_company_code,c.car_plate,c.equipment_code,c.car_type,c.vehicle_stats,c.sfdc,c.scrap_state,c.id_rfid,c.tag_rfid,c.update_date,c2.xl,c2.qyrq FROM bsth_c_cars c LEFT JOIN bsth_c_s_ccinfo c2 ON c.id = c2.cl and c2.is_cancel=0) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id ORDER BY nbbm,qyrq" 33 List<Car> list = jdbcTemplate.query("SELECT DISTINCT t1.*,t2.line_code,t2.name as line_name FROM(SELECT c.inside_code as nbbm,c.business_code as company_code,c.branche_company_code,c.car_plate,c.equipment_code,c.car_type,c.vehicle_stats,c.sfdc,c.scrap_state,c.id_rfid,c.tag_rfid,c.update_date,c2.xl,c2.qyrq FROM bsth_c_cars c LEFT JOIN bsth_c_s_ccinfo c2 ON c.id = c2.cl and c2.is_cancel=0) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id ORDER BY nbbm,qyrq"
33 , BeanPropertyRowMapper.newInstance(Car.class)); 34 , BeanPropertyRowMapper.newInstance(Car.class));
  35 + JdbcTemplate msJdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  36 + Map<String, String> code2sim = new HashMap<>();
  37 + List<Map<String, Object>> mappings = msJdbcTemplate.queryForList("select in_code,sim from bsth_c_device_sim_mapping");
  38 + for (Map<String, Object> map : mappings) {
  39 + code2sim.put((String) map.get("in_code"), (String) map.get("sim"));
  40 + }
34 41
35 Map<String, Car> map = new HashMap<>(); 42 Map<String, Car> map = new HashMap<>();
36 //过滤数据,多条线路配车的保留一条 43 //过滤数据,多条线路配车的保留一条
37 for(Car c : list){ 44 for(Car c : list){
38 map.put(c.getNbbm(), c); 45 map.put(c.getNbbm(), c);
  46 + c.setSim(code2sim.get(c.getNbbm()));
39 } 47 }
40 48
41 if(list != null && list.size() > 0) 49 if(list != null && list.size() > 0)
src/main/java/com/bsth/util/DBUtils_MS.java
1 -package com.bsth.util;  
2 -  
3 -import com.mchange.v2.c3p0.DataSources;  
4 -import org.apache.log4j.Logger;  
5 -  
6 -import javax.sql.DataSource;  
7 -import java.io.FileNotFoundException;  
8 -import java.io.IOException;  
9 -import java.sql.Connection;  
10 -import java.sql.ResultSet;  
11 -import java.sql.SQLException;  
12 -import java.sql.Statement;  
13 -import java.util.HashMap;  
14 -import java.util.Map;  
15 -import java.util.Properties;  
16 -  
17 -/**  
18 - * 网关ms库连接池  
19 - * @author PanZhao  
20 - *  
21 - */  
22 -//@Component  
23 -public class DBUtils_MS {  
24 -  
25 - private static String url = null;  
26 -  
27 - private static String username = null;  
28 -  
29 - private static String pwd = null;  
30 -  
31 - private static DataSource ds_pooled;  
32 -  
33 - static Logger logger = Logger.getLogger(DBUtils_MS.class);  
34 -  
35 - static {  
36 - Properties env = new Properties();  
37 -  
38 - try {  
39 - env.load(DBUtils_MS.class.getClassLoader().getResourceAsStream("ms-jdbc.properties"));  
40 - // 1. 加载驱动类  
41 - Class.forName(env.getProperty("ms.mysql.driver"));  
42 -  
43 - url = env.getProperty("ms.mysql.url");  
44 - username = env.getProperty("ms.mysql.username");  
45 - pwd = env.getProperty("ms.mysql.password");  
46 -  
47 - // 设置连接数据库的配置信息  
48 - DataSource ds_unpooled = DataSources.unpooledDataSource(url,  
49 - username, pwd);  
50 -  
51 - Map<String, Object> pool_conf = new HashMap<String, Object>();  
52 - // 设置最大连接数  
53 - pool_conf.put("maxPoolSize", 10);  
54 -  
55 - pool_conf.put("testConnectionOnCheckout", false);  
56 - //异步检测连接的有效性  
57 - pool_conf.put("testConnectionOnCheckin", true);  
58 - //30秒检测一次  
59 - pool_conf.put("idleConnectionTestPeriod", 30);  
60 - ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf);  
61 - } catch (FileNotFoundException e) {  
62 - logger.error(e.toString());  
63 - e.printStackTrace();  
64 - } catch (IOException e) {  
65 - logger.error(e.toString());  
66 - e.printStackTrace();  
67 - } catch (ClassNotFoundException e) {  
68 - logger.error(e.toString());  
69 - e.printStackTrace();  
70 - } catch (SQLException e) {  
71 - logger.error(e.toString());  
72 - e.printStackTrace();  
73 - }  
74 - }  
75 -  
76 - /**  
77 - * 获取连接对象  
78 - */  
79 - public static Connection getConnection() throws SQLException {  
80 - return ds_pooled.getConnection();  
81 - }  
82 -  
83 - /**  
84 - * 释放连接池资源  
85 - */  
86 - public static void clearup() {  
87 - if (ds_pooled != null) {  
88 - try {  
89 - DataSources.destroy(ds_pooled);  
90 - } catch (SQLException e) {  
91 - logger.error(e.toString());  
92 - e.printStackTrace();  
93 - }  
94 - }  
95 - }  
96 -  
97 - /**  
98 - * 资源关闭  
99 - *  
100 - * @param rs  
101 - * @param stmt  
102 - * @param conn  
103 - */  
104 - public static void close(ResultSet rs, Statement stmt, Connection conn) {  
105 - if (rs != null) {  
106 - try {  
107 - rs.close();  
108 - } catch (SQLException e) {  
109 - logger.error(e.toString());  
110 - e.printStackTrace();  
111 - }  
112 - }  
113 -  
114 - if (stmt != null) {  
115 - try {  
116 - stmt.close();  
117 - } catch (SQLException e) {  
118 - logger.error(e.toString());  
119 - e.printStackTrace();  
120 - }  
121 - }  
122 -  
123 - if (conn != null) {  
124 - try {  
125 - conn.close();  
126 - } catch (SQLException e) {  
127 - logger.error(e.toString());  
128 - e.printStackTrace();  
129 - }  
130 - }  
131 - }  
132 -  
133 - public static DataSource getDataSource(){  
134 - return ds_pooled;  
135 - }  
136 -} 1 +package com.bsth.util;
  2 +
  3 +import com.mchange.v2.c3p0.DataSources;
  4 +import org.apache.log4j.Logger;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +import javax.sql.DataSource;
  8 +import java.io.FileNotFoundException;
  9 +import java.io.IOException;
  10 +import java.sql.Connection;
  11 +import java.sql.ResultSet;
  12 +import java.sql.SQLException;
  13 +import java.sql.Statement;
  14 +import java.util.HashMap;
  15 +import java.util.Map;
  16 +import java.util.Properties;
  17 +
  18 +/**
  19 + * 网关ms库连接池
  20 + * @author PanZhao
  21 + *
  22 + */
  23 +@Component
  24 +public class DBUtils_MS {
  25 +
  26 + private static String url = null;
  27 +
  28 + private static String username = null;
  29 +
  30 + private static String pwd = null;
  31 +
  32 + private static DataSource ds_pooled;
  33 +
  34 + static Logger logger = Logger.getLogger(DBUtils_MS.class);
  35 +
  36 + static {
  37 + Properties env = new Properties();
  38 +
  39 + try {
  40 + env.load(DBUtils_MS.class.getClassLoader().getResourceAsStream("ms-jdbc.properties"));
  41 + // 1. 加载驱动类
  42 + Class.forName(env.getProperty("ms.mysql.driver"));
  43 +
  44 + url = env.getProperty("ms.mysql.url");
  45 + username = env.getProperty("ms.mysql.username");
  46 + pwd = env.getProperty("ms.mysql.password");
  47 +
  48 + // 设置连接数据库的配置信息
  49 + DataSource ds_unpooled = DataSources.unpooledDataSource(url,
  50 + username, pwd);
  51 +
  52 + Map<String, Object> pool_conf = new HashMap<String, Object>();
  53 + // 设置最大连接数
  54 + pool_conf.put("maxPoolSize", 10);
  55 +
  56 + pool_conf.put("testConnectionOnCheckout", false);
  57 + //异步检测连接的有效性
  58 + pool_conf.put("testConnectionOnCheckin", true);
  59 + //30秒检测一次
  60 + pool_conf.put("idleConnectionTestPeriod", 30);
  61 + ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf);
  62 + } catch (FileNotFoundException e) {
  63 + logger.error(e.toString());
  64 + e.printStackTrace();
  65 + } catch (IOException e) {
  66 + logger.error(e.toString());
  67 + e.printStackTrace();
  68 + } catch (ClassNotFoundException e) {
  69 + logger.error(e.toString());
  70 + e.printStackTrace();
  71 + } catch (SQLException e) {
  72 + logger.error(e.toString());
  73 + e.printStackTrace();
  74 + }
  75 + }
  76 +
  77 + /**
  78 + * 获取连接对象
  79 + */
  80 + public static Connection getConnection() throws SQLException {
  81 + return ds_pooled.getConnection();
  82 + }
  83 +
  84 + /**
  85 + * 释放连接池资源
  86 + */
  87 + public static void clearup() {
  88 + if (ds_pooled != null) {
  89 + try {
  90 + DataSources.destroy(ds_pooled);
  91 + } catch (SQLException e) {
  92 + logger.error(e.toString());
  93 + e.printStackTrace();
  94 + }
  95 + }
  96 + }
  97 +
  98 + /**
  99 + * 资源关闭
  100 + *
  101 + * @param rs
  102 + * @param stmt
  103 + * @param conn
  104 + */
  105 + public static void close(ResultSet rs, Statement stmt, Connection conn) {
  106 + if (rs != null) {
  107 + try {
  108 + rs.close();
  109 + } catch (SQLException e) {
  110 + logger.error(e.toString());
  111 + e.printStackTrace();
  112 + }
  113 + }
  114 +
  115 + if (stmt != null) {
  116 + try {
  117 + stmt.close();
  118 + } catch (SQLException e) {
  119 + logger.error(e.toString());
  120 + e.printStackTrace();
  121 + }
  122 + }
  123 +
  124 + if (conn != null) {
  125 + try {
  126 + conn.close();
  127 + } catch (SQLException e) {
  128 + logger.error(e.toString());
  129 + e.printStackTrace();
  130 + }
  131 + }
  132 + }
  133 +
  134 + public static DataSource getDataSource(){
  135 + return ds_pooled;
  136 + }
  137 +}
src/main/resources/ms-jdbc.properties
@@ -4,6 +4,6 @@ @@ -4,6 +4,6 @@
4 #ms.mysql.password= panzhao 4 #ms.mysql.password= panzhao
5 5
6 ms.mysql.driver= com.mysql.jdbc.Driver 6 ms.mysql.driver= com.mysql.jdbc.Driver
7 -ms.mysql.url= jdbc:mysql://10.10.2.20/ms?useUnicode=true&characterEncoding=utf-8 7 +ms.mysql.url= jdbc:mysql://10.10.2.20/ms?useUnicode=true&characterEncoding=utf-8&useSSL=false
8 ms.mysql.username= root 8 ms.mysql.username= root
9 ms.mysql.password= root2jsp 9 ms.mysql.password= root2jsp
10 \ No newline at end of file 10 \ No newline at end of file
src/main/resources/xxfb-jdbc.properties
@@ -4,6 +4,6 @@ @@ -4,6 +4,6 @@
4 #xxfb.mysql.password= panzhao 4 #xxfb.mysql.password= panzhao
5 5
6 xxfb.mysql.driver= com.mysql.jdbc.Driver 6 xxfb.mysql.driver= com.mysql.jdbc.Driver
7 -xxfb.mysql.url= jdbc:mysql://10.10.2.20/info_publish?useUnicode=true&characterEncoding=utf-8 7 +xxfb.mysql.url= jdbc:mysql://10.10.2.20/info_publish?useUnicode=true&characterEncoding=utf-8&useSSL=false
8 xxfb.mysql.username= root 8 xxfb.mysql.username= root
9 xxfb.mysql.password= root2jsp 9 xxfb.mysql.password= root2jsp
10 \ No newline at end of file 10 \ No newline at end of file