Commit b02c4c75cdcb480c65fecf81fff08727b623cc18

Authored by yiming
1 parent f2b93298

改为数据接口获取

src/main/java/com/example/demo/SaticScheduleTask.java
... ... @@ -3,6 +3,8 @@ package com.example.demo;
3 3  
4 4  
5 5 import com.example.demo.model.Scheduling;
  6 +import com.example.demo.model.SchedulingData;
  7 +import com.example.demo.model.StationRouteData;
6 8 import com.example.demo.service.Contrast;
7 9 import org.slf4j.Logger;
8 10 import org.slf4j.LoggerFactory;
... ... @@ -31,15 +33,40 @@ public class SaticScheduleTask {
31 33 @Autowired
32 34 private Contrast contrast;
33 35  
  36 + public static Map<String,List<SchedulingData>> SchedulingDataMap=new HashMap<>();
  37 +
  38 + public static List<List<StationRouteData>> StationRouteData=new ArrayList<>();
34 39  
35 40 @Scheduled(cron = "0 0 12 * * ?")
  41 + @PostConstruct
36 42 void getArrivalInfos(){
37 43 try {
38 44 LocalDateTime now=LocalDate.now().atStartOfDay();
39   - /*DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  45 + DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
  46 +/* DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
40 47 now=LocalDateTime.parse("2024-08-26 00:00",tdf);*/
41   - contrast.getSchedulingS(now,1);
42   - contrast.getStationRoutes();
  48 + if(SchedulingDataMap.size()==0){
  49 + List<SchedulingData> dataList1=contrast.getSchedulingS(now,1);
  50 + SchedulingDataMap.put(now.minusDays(1).format(dtf),dataList1);
  51 + logger.info(">>>>>>>>>>>>>>"+now.minusDays(1)+"路单信息加载完毕");
  52 +
  53 + List<SchedulingData> dataList2=contrast.getSchedulingS(now,2);
  54 + SchedulingDataMap.put(now.minusDays(2).format(dtf),dataList2);
  55 + logger.info(">>>>>>>>>>>>>>"+now.minusDays(2)+"路单信息加载完毕");
  56 +
  57 + List<SchedulingData> dataList3=contrast.getSchedulingS(now,3);
  58 + SchedulingDataMap.put(now.minusDays(3).format(dtf),dataList3);
  59 + logger.info(">>>>>>>>>>>>>>"+now.minusDays(3)+"路单信息加载完毕");
  60 + }else {
  61 + List<SchedulingData> dataList1=contrast.getSchedulingS(now,1);
  62 + SchedulingDataMap.put(now.minusDays(1).format(dtf),dataList1);
  63 + logger.info(">>>>>>>>>>>>>>"+now.minusDays(1)+"路单信息加载完毕");
  64 + SchedulingDataMap.remove(now.minusDays(4));
  65 + logger.info(">>>>>>>>>>>>>>"+now.minusDays(4)+"路单信息删除完毕");
  66 + }
  67 +
  68 + StationRouteData=contrast.getStationRoutes();
  69 + logger.info(">>>>>>>>>>>>>>站点路由信息加载完毕");
43 70 } catch (Exception e) {
44 71 e.printStackTrace();
45 72 }
... ...
src/main/java/com/example/demo/control/ScheduleController.java 0 → 100644
  1 +package com.example.demo.control;
  2 +
  3 +
  4 +import cn.hutool.json.JSONArray;
  5 +import cn.hutool.json.JSONUtil;
  6 +import com.example.demo.SaticScheduleTask;
  7 +import com.example.demo.model.Scheduling;
  8 +import com.example.demo.model.SchedulingData;
  9 +import com.example.demo.model.StationRoute;
  10 +import com.example.demo.model.StationRouteData;
  11 +import com.example.demo.service.Contrast;
  12 +import com.example.demo.util.IPWhiteUtil;
  13 +import com.example.demo.util.IpUtils;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.web.bind.annotation.RequestMapping;
  18 +import org.springframework.web.bind.annotation.RequestParam;
  19 +import org.springframework.web.bind.annotation.RestController;
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import java.time.LocalDateTime;
  22 +import java.time.format.DateTimeFormatter;
  23 +import java.util.List;
  24 +
  25 +
  26 +@RestController
  27 +@RequestMapping("schedule")
  28 +public class ScheduleController {
  29 +
  30 + @Autowired
  31 + private Contrast contrast;
  32 +
  33 +
  34 + private String ipWhite = "58.40.5.18;61.169.120.202;127.0.0.1;localhost";
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
  38 + @RequestMapping("getSchedules")
  39 + public JSONArray getSchedules(@RequestParam String date, HttpServletRequest request){
  40 + JSONArray jsonArray= new JSONArray();
  41 + try {
  42 + String ip=IpUtils.getIpAddr(request);
  43 + if (!IPWhiteUtil.checkRequestIP(ip, ipWhite)) {
  44 + logger.info("拦截的IP为:" + ip);
  45 + return null;
  46 + }
  47 + List<SchedulingData> list= SaticScheduleTask.SchedulingDataMap.get(date);
  48 + jsonArray = JSONUtil.parseArray(list);
  49 + } catch (Exception e) {
  50 + e.printStackTrace();
  51 + }
  52 + logger.info(">>>>>>>>>>>>>>>>路单信息返回:"+jsonArray.size());
  53 + return jsonArray;
  54 + }
  55 +
  56 + @RequestMapping("getStationRoutes")
  57 + public JSONArray getStationRoutes(HttpServletRequest request){
  58 + JSONArray jsonArray= new JSONArray();
  59 + try {
  60 + String ip=IpUtils.getIpAddr(request);
  61 + if (!IPWhiteUtil.checkRequestIP(ip, ipWhite)) {
  62 + logger.info("拦截的IP为:" + ip);
  63 + return null;
  64 + }
  65 + List<List<StationRouteData>> list= SaticScheduleTask.StationRouteData;
  66 + jsonArray = JSONUtil.parseArray(list);
  67 + } catch (Exception e) {
  68 + e.printStackTrace();
  69 + }
  70 + logger.info(">>>>>>>>>>>>>>>>站点路由信息返回:"+jsonArray.size());
  71 + return jsonArray;
  72 + }
  73 +
  74 +
  75 +}
... ...
src/main/java/com/example/demo/model/SchedulingKFK.java renamed to src/main/java/com/example/demo/model/SchedulingData.java
... ... @@ -2,7 +2,7 @@ package com.example.demo.model;
2 2  
3 3 import java.util.List;
4 4  
5   -public class SchedulingKFK{
  5 +public class SchedulingData {
6 6 private String date;//日期YYYYMMDD
7 7 private String nbbm;//车辆内部编码
8 8 private String deviceID;//车辆内部编码
... ... @@ -21,8 +21,8 @@ public class SchedulingKFK{
21 21 private List<InOutStation> inOutStations;//进出站信息
22 22  
23 23  
24   - public static SchedulingKFK getInstance(Scheduling scheduling){
25   - SchedulingKFK schedulingKFK=new SchedulingKFK();
  24 + public static SchedulingData getInstance(Scheduling scheduling){
  25 + SchedulingData schedulingKFK=new SchedulingData();
26 26 schedulingKFK.setDate(scheduling.getSchedule_date_str()!=null?scheduling.getSchedule_date_str().replace("-",""):null);
27 27 schedulingKFK.setNbbm(scheduling.getCl_zbh());
28 28 schedulingKFK.setDeviceID(scheduling.getEquipment_code());
... ...
src/main/java/com/example/demo/model/StationRoute.java
... ... @@ -6,6 +6,7 @@ public class StationRoute {
6 6 private String line_code;
7 7 private String station_name;
8 8 private String station_code;
  9 + private String shanghai_linecode;
9 10  
10 11 public String getStation_route_code() {
11 12 return station_route_code;
... ... @@ -46,4 +47,12 @@ public class StationRoute {
46 47 public void setStation_code(String station_code) {
47 48 this.station_code = station_code;
48 49 }
  50 +
  51 + public String getShanghai_linecode() {
  52 + return shanghai_linecode;
  53 + }
  54 +
  55 + public void setShanghai_linecode(String shanghai_linecode) {
  56 + this.shanghai_linecode = shanghai_linecode;
  57 + }
49 58 }
... ...
src/main/java/com/example/demo/model/StationRouteData.java 0 → 100644
  1 +package com.example.demo.model;
  2 +
  3 +public class StationRouteData {
  4 + private String stationRouteCode;
  5 + private String directions;
  6 + private String lineCode;
  7 + private String stationName;
  8 + private String stationCode;
  9 +
  10 +
  11 +
  12 + public static StationRouteData getInstance(StationRoute stationRoute){
  13 + StationRouteData stationRouteKFK=new StationRouteData();
  14 + stationRouteKFK.setStationRouteCode(stationRoute.getStation_route_code());
  15 + stationRouteKFK.setDirections(stationRoute.getDirections());
  16 + stationRouteKFK.setLineCode(stationRoute.getShanghai_linecode());
  17 + stationRouteKFK.setStationName(stationRoute.getStation_name());
  18 + stationRouteKFK.setStationCode(stationRoute.getStation_code());
  19 + return stationRouteKFK;
  20 + }
  21 +
  22 + public String getStationRouteCode() {
  23 + return stationRouteCode;
  24 + }
  25 +
  26 + public void setStationRouteCode(String stationRouteCode) {
  27 + this.stationRouteCode = stationRouteCode;
  28 + }
  29 +
  30 + public String getDirections() {
  31 + return directions;
  32 + }
  33 +
  34 + public void setDirections(String directions) {
  35 + this.directions = directions;
  36 + }
  37 +
  38 + public String getLineCode() {
  39 + return lineCode;
  40 + }
  41 +
  42 + public void setLineCode(String lineCode) {
  43 + this.lineCode = lineCode;
  44 + }
  45 +
  46 + public String getStationName() {
  47 + return stationName;
  48 + }
  49 +
  50 + public void setStationName(String stationName) {
  51 + this.stationName = stationName;
  52 + }
  53 +
  54 + public String getStationCode() {
  55 + return stationCode;
  56 + }
  57 +
  58 + public void setStationCode(String stationCode) {
  59 + this.stationCode = stationCode;
  60 + }
  61 +}
... ...
src/main/java/com/example/demo/service/Contrast.java
1 1 package com.example.demo.service;
2 2  
3   -import cn.hutool.json.JSON;
4   -import cn.hutool.json.JSONObject;
5 3 import com.example.demo.mapper.db1.SiteMapper1;
6 4 import com.example.demo.mapper.db2.SiteMapper2;
7 5 import com.example.demo.model.*;
... ... @@ -9,10 +7,7 @@ import org.slf4j.Logger;
9 7 import org.slf4j.LoggerFactory;
10 8 import org.springframework.beans.factory.annotation.Autowired;
11 9 import org.springframework.kafka.core.KafkaTemplate;
12   -import org.springframework.kafka.support.SendResult;
13 10 import org.springframework.stereotype.Service;
14   -import org.springframework.util.concurrent.ListenableFuture;
15   -import org.springframework.util.concurrent.ListenableFutureCallback;
16 11  
17 12 import java.text.SimpleDateFormat;
18 13 import java.time.*;
... ... @@ -43,7 +38,8 @@ public class Contrast {
43 38 * @Author: YM
44 39 * @Date: 2021/10/12
45 40 */
46   - public List<Scheduling> getSchedulingS(LocalDateTime now,int day) throws Exception{
  41 + public List<SchedulingData> getSchedulingS(LocalDateTime now,int day) throws Exception{
  42 + List<SchedulingData> schedulingDataList=new ArrayList<>();
47 43 List<Scheduling> schedulingS=new ArrayList<>();
48 44 Map map = new HashMap();
49 45  
... ... @@ -52,6 +48,9 @@ public class Contrast {
52 48 DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
53 49 DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
54 50 String dateTime = siteMapper1.getMaxTime(localDateTimeStart.format(df));
  51 + if(dateTime==null){
  52 + return schedulingDataList;
  53 + }
55 54 LocalDateTime localDateTimeEnd=LocalDateTime.parse(dateTime,dtf).plusMinutes(5);
56 55  
57 56 //查询路单
... ... @@ -164,12 +163,14 @@ public class Contrast {
164 163 schedulings2.add(scheduling);
165 164 }
166 165 }
167   - logger.info("共"+schedulings.size()+"个班次,未匹配进出站班次"+schedulings2.size());
168   - List<SchedulingKFK> schedulingKFKS=new ArrayList<>();
  166 +
169 167 for (Scheduling scheduling : schedulings) {
170   - SchedulingKFK schedulingKFK=SchedulingKFK.getInstance(scheduling);
171   - schedulingKFKS.add(schedulingKFK);
  168 + SchedulingData schedulingData= SchedulingData.getInstance(scheduling);
  169 + schedulingDataList.add(schedulingData);
172 170 }
  171 + logger.info("共"+schedulingDataList.size()+"个班次,未匹配进出站班次"+schedulings2.size());
  172 +
  173 + /*
173 174  
174 175 List<List<SchedulingKFK>> subList = getSubList(100, schedulingKFKS);
175 176 if(!subList.isEmpty()){
... ... @@ -193,19 +194,27 @@ public class Contrast {
193 194 });
194 195 }
195 196 });
196   - }
197   - return schedulings;
  197 + }*/
  198 + return schedulingDataList;
198 199 }
199 200  
200   - public List<List<StationRoute>> getStationRoutes(){
201   - List<List<StationRoute>> list = new ArrayList<>();
  201 + public List<List<StationRouteData>> getStationRoutes(){
  202 + List<List<StationRouteData>> list = new ArrayList<>();
202 203 List<StationRoute> StationRouteList=siteMapper1.getStationRoute();
203   - Map<String, List<StationRoute>> StationRoutes = StationRouteList.stream().collect(Collectors.groupingBy(s->s.getLine_code()+"_"+s.getDirections()));
  204 +
  205 + List<StationRouteData> routeData=new ArrayList<>();
  206 + for (StationRoute stationRoute : StationRouteList) {
  207 + StationRouteData stationRouteData= StationRouteData.getInstance(stationRoute);
  208 + routeData.add(stationRouteData);
  209 + }
  210 +
  211 + Map<String, List<StationRouteData>> StationRoutes = routeData.stream().collect(Collectors.groupingBy(s->s.getLineCode()+"_"+s.getDirections()));
204 212 StationRoutes.forEach((k,v)->{
205 213 list.add(v);
206 214 });
207 215  
208   - if(!list.isEmpty()){
  216 +
  217 + /*if(!list.isEmpty()){
209 218 Map<String, Object> map = new HashMap<>();
210 219 map.put("datatype", "stationRoute");
211 220 map.put("datas", list);
... ... @@ -222,16 +231,15 @@ public class Contrast {
222 231 logger.error("kafka发送站点路由数据异常", ex);
223 232 }
224 233 });
225   - }
226   - System.out.println(">>>>>>>>>>>>>>>>"+list.size());
  234 + }*/
227 235 return list;
228 236 }
229 237  
230   - public List<List<SchedulingKFK>> getSubList(int length, List<SchedulingKFK> list){
  238 + public List<List<SchedulingData>> getSubList(int length, List<SchedulingData> list){
231 239 int size = list.size();
232 240 int temp = size / length + 1;
233 241 boolean result = size % length == 0;
234   - List<List<SchedulingKFK>> subList = new ArrayList<>();
  242 + List<List<SchedulingData>> subList = new ArrayList<>();
235 243 for (int i = 0; i < temp; i++) {
236 244 if (i == temp - 1) {
237 245 if (result) {
... ...
src/main/java/com/example/demo/util/IPWhiteUtil.java 0 → 100644
  1 +package com.example.demo.util;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.HashSet;
  5 +import java.util.List;
  6 +import java.util.Set;
  7 +import java.util.regex.Pattern;
  8 +
  9 +/**
  10 + * @author hello_史努比
  11 + * @ClassName:IPWhiteList
  12 + * @Function: IP 白名单.
  13 + * @Reason:关于IP白名单相关.
  14 + * @Date: 2017-4-17 下午02:49:08
  15 + */
  16 +public class IPWhiteUtil {
  17 + // IP的正则
  18 + private static Pattern pattern = Pattern
  19 + .compile("(1\\d{1,2}|2[0-4]\\d|25[0-5]|\\d{1,2})\\."
  20 + + "(1\\d{1,2}|2[0-4]\\d|25[0-5]|\\d{1,2})\\."
  21 + + "(1\\d{1,2}|2[0-4]\\d|25[0-5]|\\d{1,2})\\."
  22 + + "(1\\d{1,2}|2[0-4]\\d|25[0-5]|\\d{1,2})");
  23 +
  24 + /**
  25 + * getAvaliIpList:(根据IP白名单设置获取可用的IP列表).
  26 + *
  27 + * @param ipConfig
  28 + * @return
  29 + * @date 2017-4-17 下午02:50:20
  30 + */
  31 +
  32 + private static Set<String> getAvaliIpList(String allowIp) {
  33 +
  34 + Set<String> ipList = new HashSet<String>();
  35 + for (String allow : allowIp.replaceAll("\\s", "").split(";")) {
  36 + if (allow.indexOf("*") > -1) {
  37 + String[] ips = allow.split("\\.");
  38 + String[] from = new String[]{"0", "0", "0", "0"};
  39 + String[] end = new String[]{"255", "255", "255", "255"};
  40 + List<String> tem = new ArrayList<String>();
  41 + for (int i = 0; i < ips.length; i++)
  42 + if (ips[i].indexOf("*") > -1) {
  43 + tem = complete(ips[i]);
  44 + from[i] = null;
  45 + end[i] = null;
  46 + } else {
  47 + from[i] = ips[i];
  48 + end[i] = ips[i];
  49 + }
  50 +
  51 + StringBuffer fromIP = new StringBuffer();
  52 + StringBuffer endIP = new StringBuffer();
  53 + for (int i = 0; i < 4; i++)
  54 + if (from[i] != null) {
  55 + fromIP.append(from[i]).append(".");
  56 + endIP.append(end[i]).append(".");
  57 + } else {
  58 + fromIP.append("[*].");
  59 + endIP.append("[*].");
  60 + }
  61 + fromIP.deleteCharAt(fromIP.length() - 1);
  62 + endIP.deleteCharAt(endIP.length() - 1);
  63 +
  64 + for (String s : tem) {
  65 + String ip = fromIP.toString().replace("[*]",
  66 + s.split(";")[0])
  67 + + "-"
  68 + + endIP.toString().replace("[*]", s.split(";")[1]);
  69 + if (validate(ip)) {
  70 + ipList.add(ip);
  71 + }
  72 + }
  73 + } else {
  74 + if (validate(allow)) {
  75 + ipList.add(allow);
  76 + }
  77 + }
  78 +
  79 + }
  80 +
  81 + return ipList;
  82 + }
  83 +
  84 + /**
  85 + * 对单个IP节点进行范围限定
  86 + *
  87 + * @param arg
  88 + * @return 返回限定后的IP范围,格式为List[10;19, 100;199]
  89 + */
  90 + private static List<String> complete(String arg) {
  91 + List<String> com = new ArrayList<String>();
  92 + if (arg.length() == 1) {
  93 + com.add("0;255");
  94 + } else if (arg.length() == 2) {
  95 + String s1 = complete(arg, 1);
  96 + if (s1 != null)
  97 + com.add(s1);
  98 + String s2 = complete(arg, 2);
  99 + if (s2 != null)
  100 + com.add(s2);
  101 + } else {
  102 + String s1 = complete(arg, 1);
  103 + if (s1 != null)
  104 + com.add(s1);
  105 + }
  106 + return com;
  107 + }
  108 +
  109 + private static String complete(String arg, int length) {
  110 + String from = "";
  111 + String end = "";
  112 + if (length == 1) {
  113 + from = arg.replace("*", "0");
  114 + end = arg.replace("*", "9");
  115 + } else {
  116 + from = arg.replace("*", "00");
  117 + end = arg.replace("*", "99");
  118 + }
  119 + if (Integer.valueOf(from) > 255)
  120 + return null;
  121 + if (Integer.valueOf(end) > 255)
  122 + end = "255";
  123 + return from + ";" + end;
  124 + }
  125 +
  126 + /**
  127 + * 在添加至白名单时进行格式校验
  128 + *
  129 + * @param ip
  130 + * @return
  131 + */
  132 + private static boolean validate(String ip) {
  133 + for (String s : ip.split("-"))
  134 + if (!pattern.matcher(s).matches()) {
  135 + return false;
  136 + }
  137 + return true;
  138 + }
  139 +
  140 + /**
  141 + * checkLoginIP:(根据IP,及可用Ip列表来判断ip是否包含在白名单之中).
  142 + *
  143 + * @param ip
  144 + * @param ipList
  145 + * @return
  146 + * @date 2017-4-17 下午03:01:03
  147 + */
  148 + private static boolean checkLoginIP(String ip, Set<String> ipList) {
  149 + if (ipList.isEmpty() || ipList.contains(ip) || "localhost".equals(ip))
  150 + return true;
  151 + else {
  152 + for (String allow : ipList) {
  153 + if (allow.indexOf("-") > -1) {
  154 + String[] from = allow.split("-")[0].split("\\.");
  155 + String[] end = allow.split("-")[1].split("\\.");
  156 + String[] tag = ip.split("\\.");
  157 +
  158 + // 对IP从左到右进行逐段匹配
  159 + boolean check = true;
  160 + for (int i = 0; i < 4; i++) {
  161 + int s = Integer.valueOf(from[i]);
  162 + int t = Integer.valueOf(tag[i]);
  163 + int e = Integer.valueOf(end[i]);
  164 + if (!(s <= t && t <= e)) {
  165 + check = false;
  166 + break;
  167 + }
  168 + }
  169 + if (check) {
  170 + return true;
  171 + }
  172 + }
  173 + }
  174 + }
  175 + return false;
  176 + }
  177 +
  178 + /**
  179 + * checkIP:(根据IP地址,及IP白名单设置规则判断IP是否包含在白名单).
  180 + *
  181 + * @param ip
  182 + * @param ipWhiteConfig
  183 + * @return
  184 + * @date 2017-4-17 下午03:01:37
  185 + */
  186 + public static boolean checkRequestIP(String ip, String ipWhiteConfig) {
  187 + Set<String> ipList = getAvaliIpList(ipWhiteConfig);
  188 + if (ip == null) {
  189 + return false;
  190 + }
  191 + if (ip.contains(",")) {
  192 + String[] ipArr = ip.replaceAll(" ", "").split(",");
  193 + for (int i = 0; i < ipArr.length; i++) {
  194 + String tempIp = ipArr[i];
  195 + boolean b = checkLoginIP(tempIp, ipList);
  196 + if (!b) {
  197 + return b;
  198 + }
  199 + }
  200 + return true;
  201 + } else {
  202 + return checkLoginIP(ip, ipList);
  203 + }
  204 +
  205 + }
  206 +
  207 +
  208 +// public static void main(String[] args) {
  209 +// String ipWhilte = "192.168.1.1;" + //设置单个IP的白名单
  210 +// "localhost;"+
  211 +// "192.168.2.*;" + //设置ip通配符,对一个ip段进行匹配
  212 +// "192.168.3.17-192.168.3.38;"; //设置一个IP范围
  213 +// boolean flag = IPWhiteUtil.checkLoginIP("127.0.0.1",ipWhilte);
  214 +// boolean flag2 = IPWhiteUtil.checkLoginIP("192.168.1.2",ipWhilte);
  215 +// boolean flag3 = IPWhiteUtil.checkLoginIP("192.168.3.16",ipWhilte);
  216 +// boolean flag4 = IPWhiteUtil.checkLoginIP("192.168.3.17",ipWhilte);
  217 +// System.out.println(flag); //true
  218 +// System.out.println(flag2); //false
  219 +// System.out.println(flag3); //false
  220 +// System.out.println(flag4); //true
  221 +// }
  222 +//
  223 +
  224 +}
0 225 \ No newline at end of file
... ...
src/main/java/com/example/demo/util/IpUtils.java 0 → 100644
  1 +package com.example.demo.util;
  2 +
  3 +import javax.servlet.http.HttpServletRequest;
  4 +
  5 +public class IpUtils {
  6 +
  7 + public static String getIpAddr(HttpServletRequest request) {
  8 + if (request == null) {
  9 + return "unknown";
  10 + }
  11 + String ip = request.getHeader("x-forwarded-for");
  12 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  13 + ip = request.getHeader("Proxy-Client-IP");
  14 + }
  15 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  16 + ip = request.getHeader("X-Forwarded-For");
  17 + }
  18 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  19 + ip = request.getHeader("WL-Proxy-Client-IP");
  20 + }
  21 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  22 + ip = request.getHeader("X-Real-IP");
  23 + }
  24 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  25 + ip = request.getRemoteAddr();
  26 + }
  27 + return ip;
  28 + }
  29 +}
... ...
src/main/resources/application.properties
1   -server.port=8087
  1 +server.port=19092
2 2  
3 3 spring.datasource.db1.jdbc-url=jdbc:mysql://192.168.50.213:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
4 4 spring.datasource.db1.username=root
... ...
src/main/resources/mapping/db1/Site-mapper1.xml
... ... @@ -33,7 +33,7 @@
33 33 FROM bsth_c_s_sp_info_real
34 34 LEFT JOIN bsth_c_cars cars ON cars.inside_code = cl_zbh
35 35 LEFT JOIN bsth_c_line line ON xl_bm = line.line_code
36   - WHERE (bc_type ='normal' or bc_type ='venting') and `status`=2 and schedule_date_str = '${date}'
  36 + WHERE (bc_type ='normal' or bc_type ='venting') and `status`=2 and line.shanghai_linecode is not null and line.shanghai_linecode !='' and schedule_date_str = '${date}'
37 37 order by equipment_code,fcsj_actual
38 38 </select>
39 39  
... ... @@ -41,7 +41,7 @@
41 41 <select id="getStationRoute" resultType="com.example.demo.model.StationRoute">
42 42 SELECT l.shanghai_linecode,r.station_route_code,r.directions,r.line_code,r.station_name,r.station_code
43 43 from bsth_c_line l LEFT JOIN bsth_c_stationroute r on l.line_code=r.line_code
44   - WHERE l.destroy=0 and r.destroy=0 ORDER BY line_code,directions,station_route_code
  44 + WHERE l.destroy=0 and r.destroy=0 and l.shanghai_linecode is not null and l.shanghai_linecode !='' ORDER BY line_code,directions,station_route_code
45 45 </select>
46 46  
47 47  
... ...