作者 赵超

码头调度接口

@@ -11,6 +11,7 @@ import com.air.model.SysMenu; @@ -11,6 +11,7 @@ import com.air.model.SysMenu;
11 import com.air.model.SysRole; 11 import com.air.model.SysRole;
12 import com.air.model.SysRoleType; 12 import com.air.model.SysRoleType;
13 import com.air.model.SysUser; 13 import com.air.model.SysUser;
  14 +import com.air.util.HttpUtil;
14 import com.google.gson.Gson; 15 import com.google.gson.Gson;
15 import com.jfinal.aop.Clear; 16 import com.jfinal.aop.Clear;
16 import com.jfinal.kit.HashKit; 17 import com.jfinal.kit.HashKit;
@@ -20,6 +21,7 @@ import com.jfinal.plugin.activerecord.Page; @@ -20,6 +21,7 @@ import com.jfinal.plugin.activerecord.Page;
20 import com.teplot.common.Encrypt; 21 import com.teplot.common.Encrypt;
21 import com.teplot.common.Response; 22 import com.teplot.common.Response;
22 23
  24 +
23 /** 25 /**
24 * Depiction:后台用户管理 26 * Depiction:后台用户管理
25 * <p> 27 * <p>
@@ -92,7 +94,7 @@ public class SysUserController extends AbsController { @@ -92,7 +94,7 @@ public class SysUserController extends AbsController {
92 String SAMLResponse = getPara("SAMLResponse"); 94 String SAMLResponse = getPara("SAMLResponse");
93 String providerId = getPara("providerId"); 95 String providerId = getPara("providerId");
94 String param = "SAMLResponse=" + SAMLResponse + "&providerId=" + providerId; 96 String param = "SAMLResponse=" + SAMLResponse + "&providerId=" + providerId;
95 - String json = HttpKit.post(url, param); 97 + String json = HttpUtil.sendData(url, SAMLResponse, providerId);
96 Gson gson = new Gson(); 98 Gson gson = new Gson();
97 Kv map = gson.fromJson(json, Kv.class); 99 Kv map = gson.fromJson(json, Kv.class);
98 if (map != null) { 100 if (map != null) {
  1 +package com.air.util;
  2 +
  3 +import okhttp3.FormBody;
  4 +import okhttp3.MediaType;
  5 +import okhttp3.OkHttpClient;
  6 +import org.omg.CORBA.Request;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import sun.net.www.protocol.http.HttpURLConnection;
  10 +import sun.rmi.runtime.Log;
  11 +
  12 +import javax.xml.ws.Response;
  13 +import java.io.*;
  14 +import java.net.MalformedURLException;
  15 +import java.net.URL;
  16 +import java.net.URLEncoder;
  17 +import java.util.Map;
  18 +
  19 +/**
  20 + * Created by XYH on 2019/1/22.
  21 + */
  22 +public class HttpUtil {
  23 + static Logger logger = LoggerFactory.getLogger(HttpUtil.class);
  24 + public static String sendData(String url, String SAMLResponse,String providerId) {
  25 + StringBuilder str = new StringBuilder();
  26 + BufferedReader bf = null;
  27 + OutputStreamWriter writer = null;
  28 + String param= null;
  29 + String param2=null;
  30 + try {
  31 + param = "SAMLResponse="+ URLEncoder.encode(SAMLResponse,"UTF-8")+"&"+"providerId="+providerId;
  32 +
  33 + } catch (UnsupportedEncodingException e) {
  34 + e.printStackTrace();
  35 + }
  36 + try {
  37 + URL Url = new URL(url);
  38 + HttpURLConnection conn = (HttpURLConnection) Url.openConnection();
  39 + conn.setDoInput(true);
  40 + conn.setDoOutput(true);
  41 + //conn.setRequestProperty("X-Rrquested-With", "XMLHttpRequest");
  42 + //conn.setRequestProperty("Connection", "keep-alive");
  43 + //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
  44 + conn.setRequestMethod("POST");
  45 + conn.connect();
  46 + StringBuffer params = new StringBuffer();
  47 + //表单参数与get形式一样
  48 + //params.append("SAMLResponse").append("=").append(SAMLResponse).append("&")
  49 + // .append("providerId").append("=").append(providerId);
  50 + writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
  51 + writer.write(param);
  52 + writer.flush();
  53 + bf = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
  54 + String inputLine = null;
  55 + while ((inputLine = bf.readLine()) != null) {
  56 + str.append(inputLine);
  57 + }
  58 + } catch (MalformedURLException e) {
  59 + e.printStackTrace();
  60 + } catch (IOException e) {
  61 + e.printStackTrace();
  62 + } finally {
  63 + try {
  64 + writer.close();
  65 + bf.close();
  66 + } catch (IOException e) {
  67 + e.printStackTrace();
  68 + }
  69 + }
  70 + return str.toString();
  71 + }
  72 +
  73 +}
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 <html lang="zh"> 2 <html lang="zh">
3 #@header() 3 #@header()
4 4
  5 +<script type="text/javascript" src="#(contextPath)/js/portCarEdit.js?ver=#(version)"></script>
5 <body> 6 <body>
6 <div> 7 <div>
7 <ol class="breadcrumb"> 8 <ol class="breadcrumb">
@@ -69,8 +70,8 @@ @@ -69,8 +70,8 @@
69 70
70 <tr id="leftPortTr" style="display:none;width: 100%;"> 71 <tr id="leftPortTr" style="display:none;width: 100%;">
71 <td>码头</td> 72 <td>码头</td>
72 - <td><select id="leftList" class="input-small m-wrap" tabindex="1" style="width: 160px;"  
73 - name="car.portNo" required> 73 + <td><select id="leftList" class="input-small m-wrap" tabindex="2" style="width: 160px;"
  74 + name="car.portNo" >
74 <option value="">选择离港码头</option> 75 <option value="">选择离港码头</option>
75 #for(port : leftList) 76 #for(port : leftList)
76 <option value="#(port.portNo)" 77 <option value="#(port.portNo)"
@@ -83,8 +84,7 @@ @@ -83,8 +84,7 @@
83 #end 84 #end
84 </select> 85 </select>
85 </td> 86 </td>
86 - </tr>  
87 - 87 + </tr>
88 <tr> 88 <tr>
89 <td>特殊</td> 89 <td>特殊</td>
90 <td colspan="2"> 90 <td colspan="2">
@@ -104,9 +104,6 @@ @@ -104,9 +104,6 @@
104 </form> 104 </form>
105 </div> 105 </div>
106 </div> 106 </div>
107 -  
108 -<script type="text/javascript" src="#(contextPath)/js/portCarEdit.js?ver=#(version)"></script>  
109 -  
110 <script type="text/javascript"> 107 <script type="text/javascript">
111 #if(flag) 108 #if(flag)
112 showTip('#(flag)'); 109 showTip('#(flag)');
@@ -66,7 +66,7 @@ public class CarController extends AbsController { @@ -66,7 +66,7 @@ public class CarController extends AbsController {
66 Map<String, Object> maps = new HashMap<String, Object>(); 66 Map<String, Object> maps = new HashMap<String, Object>();
67 maps.put("carNo", carNo); 67 maps.put("carNo", carNo);
68 maps.put("stationArea", stationArea); 68 maps.put("stationArea", stationArea);
69 - AirPortCar car = AirPortCar.dao.searchFirst(maps); 69 + AirPortCar car = AirPortCar.dao.searchFirst1(maps);
70 AirPort port = AirPort.dao.free(car.getStationArea(), car.getIsPickup()); 70 AirPort port = AirPort.dao.free(car.getStationArea(), car.getIsPickup());
71 if (port == null) { 71 if (port == null) {
72 return false; 72 return false;
@@ -92,7 +92,8 @@ public class CarController extends AbsController { @@ -92,7 +92,8 @@ public class CarController extends AbsController {
92 Map<String, Object> maps = new HashMap<String, Object>(); 92 Map<String, Object> maps = new HashMap<String, Object>();
93 maps.put("carNo", carNo); 93 maps.put("carNo", carNo);
94 maps.put("stationArea", stationArea); 94 maps.put("stationArea", stationArea);
95 - AirPortCar car = AirPortCar.dao.searchFirst(maps); 95 + AirPortCar.dao.update(carNo);
  96 + AirPortCar car = AirPortCar.dao.searchFirst1(maps);
96 car.setStatus(AirPortCarStatus.LEFT.ordinal()); 97 car.setStatus(AirPortCarStatus.LEFT.ordinal());
97 car.setLeaveTime(new Date()); 98 car.setLeaveTime(new Date());
98 if (car.update()) { 99 if (car.update()) {
@@ -107,22 +108,22 @@ public class CarController extends AbsController { @@ -107,22 +108,22 @@ public class CarController extends AbsController {
107 String gateTypeCode = getPara("stationCode"); 108 String gateTypeCode = getPara("stationCode");
108 StationGateType gateType = new StationGateType(gateTypeCode); 109 StationGateType gateType = new StationGateType(gateTypeCode);
109 Log.getLog(getClass()).error("gateType-->" + gateType.toString()); 110 Log.getLog(getClass()).error("gateType-->" + gateType.toString());
110 -  
111 String stationArea = gateType.getAreaCode();// 货站区域代码 111 String stationArea = gateType.getAreaCode();// 货站区域代码
112 String carNo = getPara("carNo");// 车牌号 112 String carNo = getPara("carNo");// 车牌号
113 - 113 + Boolean isPickup = getParaToBoolean("isPickup");
  114 + System.out.println(isPickup);
114 if (StrKit.notBlank(carNo)) { 115 if (StrKit.notBlank(carNo)) {
115 carNo = carNo.toUpperCase(); 116 carNo = carNo.toUpperCase();
116 } 117 }
117 -  
118 GateType type = gateType.getType();// 0 进场;1 出场; 118 GateType type = gateType.getType();// 0 进场;1 出场;
119 -  
120 Response ret = new Response(CODE_FAILURE); 119 Response ret = new Response(CODE_FAILURE);
121 if (!StrKit.isBlank(stationArea)) { 120 if (!StrKit.isBlank(stationArea)) {
122 if (!StrKit.isBlank(carNo)) { 121 if (!StrKit.isBlank(carNo)) {
123 if (type != GateType.ERROR) { 122 if (type != GateType.ERROR) {
124 - ret = dealCar(stationArea, carNo, type); 123 + ret = dealCar(stationArea, carNo, type, isPickup);
  124 +
125 } else { 125 } else {
  126 +
126 ret.setMsg("无法判断进出场类型"); 127 ret.setMsg("无法判断进出场类型");
127 } 128 }
128 } else { 129 } else {
@@ -137,55 +138,88 @@ public class CarController extends AbsController { @@ -137,55 +138,88 @@ public class CarController extends AbsController {
137 /** 138 /**
138 * 处理卡口数据 139 * 处理卡口数据
139 * 140 *
140 - * @param stationArea  
141 - * 货站区域代码  
142 - * @param carNo  
143 - * 车牌号  
144 - * @param type  
145 - * 进出场类型 {@link GateType} 141 + * @param stationArea 货站区域代码
  142 + * @param carNo 车牌号
  143 + * @param type 进出场类型 {@link GateType}
146 */ 144 */
147 - private Response dealCar(String stationArea, String carNo, GateType type) { 145 + private Response dealCar(String stationArea, String carNo, GateType type, boolean isPickup) {
148 Response ret = new Response(CODE_FAILURE); 146 Response ret = new Response(CODE_FAILURE);
149 Map<String, Object> maps = new HashMap<String, Object>(); 147 Map<String, Object> maps = new HashMap<String, Object>();
150 maps.put("carNo", carNo); 148 maps.put("carNo", carNo);
151 maps.put("stationArea", stationArea); 149 maps.put("stationArea", stationArea);
152 - AirPortCar old = AirPortCar.dao.searchFirst(maps); 150 + AirPortCar old = AirPortCar.dao.searchFirst1(maps);
  151 + System.out.println(old);
153 if (old != null) { 152 if (old != null) {
154 AirPortCarStatus status = AirPortCarStatus.valueOf(old.getStatus()); 153 AirPortCarStatus status = AirPortCarStatus.valueOf(old.getStatus());
155 - if (AirPortCarStatus.APPLY == status && type == GateType.JIN) {  
156 - // 待进场状态,可进场  
157 - old.setStatus(AirPortCarStatus.ENTER.ordinal());  
158 - if (enter(carNo, stationArea)) {  
159 - // 进场成功  
160 - ret = new Response(CODE_SUCCESS);  
161 - ret.setMsg("进场成功");  
162 - old = AirPortCar.dao.searchFirst(maps);  
163 - LedKit.sendBigLedScreen(LedKit.bigLedText(old.getPortNo(), old.getIsPickup(), carNo, stationArea),  
164 - stationArea);  
165 - LedKit.nextCar(stationArea, old.getPortNo(), old.getIsPickup());  
166 - } else {  
167 - ret.setMsg("进场失败");  
168 - }  
169 - } else if (AirPortCarStatus.ENTER == status && type == GateType.CHU) {  
170 - // 已进场状态,可出场  
171 - if (exit(carNo, stationArea)) {  
172 - // 成功出场  
173 - ret = new Response(CODE_SUCCESS);  
174 - ret.setMsg("出场成功");  
175 - LedKit.nextCar(stationArea, old.getPortNo(), old.getIsPickup()); 154 + // 查询最近一条数据状态如果是进场状态
  155 + if (AirPortCarStatus.ENTER == status && type == GateType.JIN) {
  156 + ret.setMsg("无法重复进场");
  157 + //查询最近插入的数据离场出去判断离场
  158 + }else if(AirPortCarStatus.LEFT == status && type == GateType.CHU){
  159 + ret.setMsg("无法重复出场");
  160 + }else{
  161 + //如果已经来过车辆 重新输入
  162 + //如果是进场插入最新的数据 并改变数值
  163 + if (AirPortCarStatus.LEFT == status && type == GateType.JIN) {
  164 + AirPortCar model = new AirPortCar();
  165 + System.out.println(isPickup);
  166 + model.setIsPickup(isPickup);
  167 + model.setCarNo(carNo);
  168 + model.setStationArea(stationArea);
  169 + if (model.save()) {
  170 + } else {
  171 + ret.setMsg("数据录入错误");
  172 + }
  173 + }
  174 + //重新赋值新的的值
  175 + old = AirPortCar.dao.searchFirst1(maps);
  176 + status = AirPortCarStatus.valueOf(old.getStatus());
  177 + if (AirPortCarStatus.APPLY == status && type == GateType.JIN) {
  178 + // 待进场状态,可进场
  179 + old.setStatus(AirPortCarStatus.ENTER.ordinal());
  180 + if (enter(carNo, stationArea)) {
  181 + // 进场成功
  182 + ret = new Response(CODE_SUCCESS);
  183 + ret.setMsg("进场成功");
  184 + old = AirPortCar.dao.searchFirst1(maps);
  185 + LedKit.sendBigLedScreen(
  186 + LedKit.bigLedText(old.getPortNo(), old.getIsPickup(), carNo, stationArea), stationArea);
  187 + LedKit.nextCar(stationArea, old.getPortNo(), old.getIsPickup());
  188 + } else {
  189 + ret.setMsg("进场失败");
  190 + }
  191 + } else if (AirPortCarStatus.ENTER == status && type == GateType.CHU) {
  192 + // 已进场状态,可出场
  193 + if (exit(carNo, stationArea)) {
  194 + // 成功出场
  195 + ret = new Response(CODE_SUCCESS);
  196 + ret.setMsg("出场成功");
  197 + LedKit.nextCar(stationArea, old.getPortNo(), old.getIsPickup());
  198 + } else {
  199 + // 出场失败
  200 + ret.setMsg("出场失败");
  201 + }
  202 + }
  203 + LedKit.recovery();
  204 +
  205 + }
  206 +
  207 + } else {
  208 + //如果为空插入数据
  209 + if (type == GateType.JIN) {
  210 + AirPortCar model = new AirPortCar();
  211 + System.out.println(isPickup);
  212 + model.setIsPickup(isPickup);
  213 + model.setCarNo(carNo);
  214 + model.setStationArea(stationArea);
  215 + if (model.save()) {
  216 + ret = dealCar(stationArea, carNo, type, isPickup);
176 } else { 217 } else {
177 - // 出场失败  
178 - ret.setMsg("出场失败"); 218 + ret.setMsg("数据录入错误");
179 } 219 }
180 - } else {  
181 - ret.setMsg("无法重复出场或者进场"); 220 + }else {
  221 + ret.setMsg("本车未曾进站");
182 } 222 }
183 -  
184 - LedKit.recovery();  
185 -  
186 - } else {  
187 - // 货代没有提前录入进场数据,无法分配码头  
188 - ret.setMsg("货代没有提前录入进场数据,无法分配码头");  
189 } 223 }
190 224
191 return ret; 225 return ret;
1 package com.air.led; 1 package com.air.led;
2 2
  3 +import java.util.Date;
3 import java.util.HashMap; 4 import java.util.HashMap;
4 import java.util.List; 5 import java.util.List;
5 import java.util.Map; 6 import java.util.Map;
6 - 7 +import com.jfinal.log.Log;
7 import com.air.model.AirPortCar; 8 import com.air.model.AirPortCar;
8 import com.air.model.AirPortCarStatus; 9 import com.air.model.AirPortCarStatus;
9 import com.jfinal.kit.HttpKit; 10 import com.jfinal.kit.HttpKit;
  11 +import com.jfinal.log.Log;
10 import com.jfinal.plugin.activerecord.Db; 12 import com.jfinal.plugin.activerecord.Db;
11 13
12 /** 14 /**
@@ -20,7 +22,7 @@ import com.jfinal.plugin.activerecord.Db; @@ -20,7 +22,7 @@ import com.jfinal.plugin.activerecord.Db;
20 * 22 *
21 */ 23 */
22 public class LedKit { 24 public class LedKit {
23 - final static String LED_API = "http://10.50.3.66:21890/LEDAPI.ashx"; 25 + final static String LED_API = "http://10.50.3.66:8080/LEDAPI.ashx";
24 final static String APP_KEY = "93FCC7C01F0E410EACC0A1692BD1B7A1"; 26 final static String APP_KEY = "93FCC7C01F0E410EACC0A1692BD1B7A1";
25 27
26 public LedKit() { 28 public LedKit() {
@@ -43,17 +45,16 @@ public class LedKit { @@ -43,17 +45,16 @@ public class LedKit {
43 45
44 String sql = "select * from " + AirPortCar.dao.table(); 46 String sql = "select * from " + AirPortCar.dao.table();
45 sql += " where stationArea='" + stationArea + "'"; 47 sql += " where stationArea='" + stationArea + "'";
46 - sql += " and isPickup='" + isPickUp + "'"; 48 + sql += " and isPickup=" + isPickUp + "";
47 sql += " and status=" + AirPortCarStatus.ENTER.ordinal(); 49 sql += " and status=" + AirPortCarStatus.ENTER.ordinal();
48 sql += " and portNo=" + port; 50 sql += " and portNo=" + port;
49 - String orderBy = " order by updateTime asc"; 51 + String orderBy = " order by ID asc";
50 sql += orderBy; 52 sql += orderBy;
51 AirPortCar model = AirPortCar.dao.findFirst(sql); 53 AirPortCar model = AirPortCar.dao.findFirst(sql);
52 String carNo = "空闲"; 54 String carNo = "空闲";
53 if (model != null) { 55 if (model != null) {
54 carNo = model.getCarNo(); 56 carNo = model.getCarNo();
55 } 57 }
56 -  
57 LedKit.senPortLedScreen(carNo, stationArea, port, isPickUp); 58 LedKit.senPortLedScreen(carNo, stationArea, port, isPickUp);
58 } 59 }
59 60
@@ -72,13 +73,15 @@ public class LedKit { @@ -72,13 +73,15 @@ public class LedKit {
72 try { 73 try {
73 final Map<String, String> queryParas = new HashMap<String, String>(); 74 final Map<String, String> queryParas = new HashMap<String, String>();
74 queryParas.put("appkey", APP_KEY); 75 queryParas.put("appkey", APP_KEY);
75 - 76 + System.out.println(msg+stationArea+portNo+isPickUp);
76 LedJson led = new LedJson(Led.getLed(portNo, isPickUp), 1, msg); 77 LedJson led = new LedJson(Led.getLed(portNo, isPickUp), 1, msg);
77 queryParas.put("jsonValues", led.toString()); 78 queryParas.put("jsonValues", led.toString());
78 - 79 + System.out.println(queryParas);
79 new Thread() { 80 new Thread() {
80 public void run() { 81 public void run() {
81 - HttpKit.get(LED_API, queryParas); 82 + String msg= HttpKit.get(LED_API, queryParas);
  83 + System.out.println(msg);
  84 +
82 } 85 }
83 }.start(); 86 }.start();
84 } catch (Exception e) { 87 } catch (Exception e) {
@@ -43,7 +43,7 @@ public class AirPort extends BaseAirPort<AirPort> { @@ -43,7 +43,7 @@ public class AirPort extends BaseAirPort<AirPort> {
43 public AirPort free(String stationArea, boolean isArrival) { 43 public AirPort free(String stationArea, boolean isArrival) {
44 String sql = "select * from " + table(); 44 String sql = "select * from " + table();
45 sql += " where stationArea='" + stationArea + "'"; 45 sql += " where stationArea='" + stationArea + "'";
46 - sql += " and isArrival='" + isArrival + "'"; 46 + sql += " and isArrival=" + isArrival + "";
47 String orderBy = " order by waitCount asc"; 47 String orderBy = " order by waitCount asc";
48 sql += orderBy; 48 sql += orderBy;
49 49
@@ -51,7 +51,21 @@ public class AirPort extends BaseAirPort<AirPort> { @@ -51,7 +51,21 @@ public class AirPort extends BaseAirPort<AirPort> {
51 51
52 return AirPort.dao.findFirst(sql); 52 return AirPort.dao.findFirst(sql);
53 } 53 }
54 - 54 + /**
  55 + * 查询某个货站最空闲的码头(没有进港业务(即提货)
  56 + *
  57 + * @param stationArea
  58 + * 货站的区域代码
  59 + * @return
  60 + */
  61 + public AirPort freetwo(String stationArea) {
  62 + String sql = "select * from " + table();
  63 + sql += " where stationArea='" + stationArea + "'";
  64 + String orderBy = " order by waitCount asc";
  65 + sql += orderBy;
  66 + Log.getLog(getClass()).error("sql-->" + sql);
  67 + return AirPort.dao.findFirst(sql);
  68 + }
55 public boolean enter(String stationArea, boolean isArrival, int portNo) { 69 public boolean enter(String stationArea, boolean isArrival, int portNo) {
56 Map<String, Object> maps = new HashMap<String, Object>(); 70 Map<String, Object> maps = new HashMap<String, Object>();
57 maps.put("stationArea", stationArea); 71 maps.put("stationArea", stationArea);
@@ -71,7 +85,7 @@ public class AirPort extends BaseAirPort<AirPort> { @@ -71,7 +85,7 @@ public class AirPort extends BaseAirPort<AirPort> {
71 maps.put("stationArea", stationArea); 85 maps.put("stationArea", stationArea);
72 maps.put("isArrival", isArrival); 86 maps.put("isArrival", isArrival);
73 maps.put("portNo", portNo); 87 maps.put("portNo", portNo);
74 - AirPort model = AirPort.dao.searchFirst(maps); 88 + AirPort model = AirPort.dao.searchFirst1(maps);
75 if (model != null) { 89 if (model != null) {
76 int count = model.getWaitCount() - 1; 90 int count = model.getWaitCount() - 1;
77 if (count < 0) { 91 if (count < 0) {
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 #jdbc.user=root 3 #jdbc.user=root
4 #jdbc.password=William2018!@# 4 #jdbc.password=William2018!@#
5 5
6 -jdbc.url = jdbc:mysql://127.0.0.7:3306/cgowds?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useUnicode=true&useSSL=false  
7 -jdbc.user=root 6 +jdbc.url = jdbc:mysql://localhost:3306/cgowds?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useUnicode=true&useSSL=false
  7 +jdbc.user=wds
8 jdbc.password=vmvnv1v2 8 jdbc.password=vmvnv1v2
9 9
10 #about case 10 #about case