From 3e242903008f50818729fe17a4fa38e0b1f02551 Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期三, 19 二月 2025 16:44:58 +0800 Subject: [PATCH] jtt808初始化 --- server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java | 94 ++++++- /dev/null | 356 -------------------------------- server/services/src/main/java/com/doumee/core/constants/Constants.java | 1 server/services/src/main/java/com/doumee/core/utils/StringTools.java | 2 server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java | 2 server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java | 162 ++++++++----- 6 files changed, 175 insertions(+), 442 deletions(-) diff --git a/server/services/src/main/java/com/doumee/core/constants/Constants.java b/server/services/src/main/java/com/doumee/core/constants/Constants.java index 7fc46d3..a732f80 100644 --- a/server/services/src/main/java/com/doumee/core/constants/Constants.java +++ b/server/services/src/main/java/com/doumee/core/constants/Constants.java @@ -41,6 +41,7 @@ public static final String PROJECT_FILE = "PROJECT_FILE"; public static final String PROJECTS = "PROJECTS"; public static final String DISCOUNT = "DISCOUNT"; + public static final String ELEC_BIKE_CONTRIL_API_URL = "ELEC_BIKE_CONTRIL_API_URL"; public static final String FORCE_BACK_LOCK = "FORCE_BACK_LOCK"; public static final String FORCE_BACK_SITE = "FORCE_BACK_SITE"; //杞﹁締绫诲瀷鏁版嵁 diff --git a/server/services/src/main/java/com/doumee/core/utils/HttpUtil.java b/server/services/src/main/java/com/doumee/core/utils/HttpUtil.java deleted file mode 100644 index aa8f61c..0000000 --- a/server/services/src/main/java/com/doumee/core/utils/HttpUtil.java +++ /dev/null @@ -1,356 +0,0 @@ -package com.doumee.core.utils; - -import com.alibaba.fastjson.JSONObject; -import org.apache.commons.codec.binary.Hex; -//import org.apache.commons.httpclient.HttpClient; -//import org.apache.commons.httpclient.NameValuePair; -//import org.apache.commons.httpclient.methods.PostMethod; -//import org.apache.commons.httpclient.params.HttpMethodParams; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.*; -import org.apache.http.util.EntityUtils; - -import java.io.*; -import java.lang.reflect.Field; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class HttpUtil { - public static final String UTF8 = "UTF-8"; - - /** - * @param urlpath - * @throws IOException - * @throws UnsupportedEncodingException - */ - public static String postRequestConn(String urlpath) throws UnsupportedEncodingException, IOException { - String sendString = ""; - - // 鍒涘缓url瀵硅薄 - URL url = new URL(urlpath); - - // 鎵撳紑url杩炴帴 - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestProperty("Content-Type", "application/octet-stream"); - // 璁剧疆url璇锋眰鏂瑰紡 鈥榞et鈥� 鎴栬�� 鈥榩ost鈥� - connection.setRequestMethod("POST"); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setUseCaches(true); - connection.setConnectTimeout(3000); - connection.setReadTimeout(10000); - connection.setRequestProperty("Charset", "UTF-8"); - int responseCode = connection.getResponseCode(); - if (HttpURLConnection.HTTP_OK == responseCode) { - String readLine; - BufferedReader responseReader; - StringBuffer sb = new StringBuffer(); - responseReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - while ((readLine = responseReader.readLine()) != null) { - sb.append(readLine).append("\n"); - } - responseReader.close(); - sendString = sb.toString(); - // httpConn.disconnect(); - } else { - System.out.println("error"); - } - - return sendString; - } - - /** - * @param urlPath - * @param json - * @throws IOException - * @throws UnsupportedEncodingException - */ - public static String postRequestConn(String urlPath, String json,String tokenStr) throws UnsupportedEncodingException, IOException { - String sendString = ""; - // try { - URL url; - url = new URL(urlPath); - HttpURLConnection httpConn; - httpConn = (HttpURLConnection) url.openConnection(); - // httpConn.connect(); - httpConn.setDoOutput(true); - httpConn.setDoInput(true); - httpConn.setRequestMethod("POST"); - httpConn.setUseCaches(false); - httpConn.setInstanceFollowRedirects(true); - httpConn.setRequestProperty("Content-Type", "application/json"); - httpConn.setRequestProperty("accept", "application/json"); - httpConn.setRequestProperty("X-Judge-Server-Token",getSHA256Str(tokenStr)); - httpConn.setConnectTimeout(10000); - httpConn.setReadTimeout(10000); - httpConn.connect(); - OutputStream out = httpConn.getOutputStream(); - byte[] data = (json.toString()).getBytes("UTF-8"); - out.write(data, 0, data.length); - out.flush(); - out.close(); - int responseCode = httpConn.getResponseCode(); - if (HttpURLConnection.HTTP_OK == responseCode) { - String readLine; - BufferedReader responseReader; - StringBuffer sb = new StringBuffer(); - responseReader = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8")); - while ((readLine = responseReader.readLine()) != null) { - sb.append(readLine); - } - responseReader.close(); - sendString = sb.toString(); - // httpConn.disconnect(); - } else { - System.out.println("error"); - } - return sendString; - } - - public static String doPost(String url,JSONObject json,String token) { - DefaultHttpClient client = new DefaultHttpClient(); - HttpPost post = new HttpPost(url); - String response = null; - try { - post.addHeader("Content-Type", "application/json; charset=utf-8"); - post.addHeader("X-Judge-Server-Token",getSHA256Str(token)); - StringEntity s = new StringEntity(json.toString()); - s.setContentEncoding("UTF-8"); - s.setContentType("application/json");//鍙戦�乯son鏁版嵁闇�瑕佽缃甤ontentType - post.setEntity(s); - HttpResponse res = client.execute(post); - if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - HttpEntity entity = res.getEntity(); - response = EntityUtils.toString(entity);// 杩斿洖json鏍煎紡锛� - } - } catch (Exception e) { - throw new RuntimeException(e); - } - // System.out.print(response); - return response; - } - - //java瀵硅薄杞琺ap - public static Map<String, Object> objectToMap(Object obj) throws Exception { - if (obj == null) { - return null; - } - Map<String, Object> map = new HashMap<>(); - Field[] declaredFields = obj.getClass().getDeclaredFields(); - for (Field field : declaredFields) { - field.setAccessible(true); - map.put(field.getName(), field.get(obj)); - } - return map; - } -// public static String doFormPost(String url,JSONObject json) throws Exception{ -// String response = null; -// HttpClient client = new HttpClient(); -// PostMethod postMethod = new PostMethod(url); -// postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8"); -// Map<String, Object> params =objectToMap(json); -// if(params !=null && params.get("map") !=null ){ -// HashMap<String,String> map = (HashMap<String, String>) params.get("map"); -// if(map !=null && !map.isEmpty()){ -// NameValuePair[] data = new NameValuePair[map.size()]; -// int i =0; -// for(Map.Entry<String,String> entry : map.entrySet()){ -// data[i] = new NameValuePair(entry.getKey(),entry.getValue()); -// i++; -// } -// postMethod.setRequestBody(data); -// } -// } -// try { -// client.executeMethod(postMethod); -// if(postMethod.getStatusCode() == HttpStatus.SC_OK){ -// response = postMethod.getResponseBodyAsString(); -// } -// }catch (Exception e){ -// e.printStackTrace(); -// } -// return response; -// } - - - public static void main(String[] args) throws IOException { -// "language_config": sub_config["config"], -// "src": code, -// "max_cpu_time": self.problem.time_limit, -// "max_memory": 1024 * 1024 * self.problem.memory_limit, -// "test_case_id": self.problem.test_case_id, -// "output": False, -// "spj_version": self.problem.spj_version, -// "spj_config": spj_config.get("config"), -// "spj_compile_config": spj_config.get("compile"), -// "spj_src": self.problem.spj_code, -// "io_mode": self.problem.io_mode -/* - { - "template": "" , - - "compile": { - "src_name": "main.cpp", - "exe_name": "main", - "max_cpu_time": 10000, - "max_real_time": 20000, - "max_memory": 1024 * 1024 * 1024, - "compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}", - }, - "run": { - "command": "{exe_path}", - "seccomp_rule": {ProblemIOMode.standard: "c_cpp", ProblemIOMode.file: "c_cpp_file_io"}, - "env": default_env - } - - {"config": _cpp_lang_config, "spj": {"compile": _cpp_lang_spj_compile, "config": _cpp_lang_spj_config}, - "name": "C++", "description": "G++ 5.4", "content_type": "text/x-c++src"},*/ - JSONObject json =new JSONObject(); - JSONObject j = new JSONObject(); - JSONObject spj = new JSONObject(); - JSONObject sc = new JSONObject(); - sc.put("src_name","spj-{spj_version}.cpp"); - sc.put("exe_name","spj-{spj_version}"); - sc.put("max_cpu_time",10000); - sc.put("max_real_time",20000); - sc.put("max_memory",1024 * 1024 * 1024); - sc.put("compile_command","/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}"); - spj.put("compile",sc); - JSONObject scc = new JSONObject(); - scc.put("exe_name","spj-{spj_version}"); - scc.put("command","{exe_path} {in_file_path} {user_out_file_path}"); - scc.put("seccomp_rule","c_cpp"); - spj.put("config",scc); - JSONObject compile = new JSONObject(); - compile.put("src_name", "main.cpp"); - compile.put("exe_name", "main"); - compile.put("max_cpu_time", 10000); - compile.put("max_real_time", 20000); - compile.put("max_memory",1024 * 1024 * 1024); - compile.put("compile_command", "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++14 {src_path} -lm -o {exe_path}"); - JSONObject run = new JSONObject(); - JSONObject sr = new JSONObject(); - sr.put("Standard IO","c_cpp"); - sr.put("File IO","c_cpp_file_io"); - run.put("command", "{exe_path}"); - run.put("seccomp_rule", sr); - run.put("env",new String[]{"LANG=en_US.UTF-8", "LANGUAGE=en_US:en", "LC_ALL=en_US.UTF-8"}); - JSONObject config = new JSONObject(); - config.put("template","//PREPEND BEGIN\n" + - "#include <iostream>\n" + - "//PREPEND END\n" + - "\n" + - "//TEMPLATE BEGIN\n" + - "int add(int a, int b) {\n" + - " // Please fill this blank\n" + - " return ___________;\n" + - "}\n" + - "//TEMPLATE END\n" + - "\n" + - "//APPEND BEGIN\n" + - "int main() {\n" + - " std::cout << add(1, 2);\n" + - " return 0;\n" + - "}\n" + - "//APPEND END"); - config.put("run",run); - config.put("compile",compile); - - j.put("name","C++"); - j.put("description","G++ 5.4"); - j.put("content_type","text/x-c++src"); - j.put("config",config); - j.put("spj",spj); - - json.put("language_config",j.get("config")); - json.put("src","#include <stdio.h> // puts \n" + - "int main(){\n" + - " puts(\"Hello,World!\");// 杈撳嚭\n" + - "}"); - json.put("max_cpu_time",1000); - json.put("max_memory",1024*1024*64); - json.put("test_case_id","2b7e2f6a801b6c00388e717ae11b6f57"); -// json.put("output",Boolean.FALSE); -// json.put("spj_version",""); -// json.put("spj_config",""); -// json.put("spj_compile_config",""); -// json.put("spj_src",""); -// json.put("io_mode","{\"input\": \"input.in\", \"output\": \"output.out\", \"io_mode\": \"Standard IO\"}"); - - System.out.println(json.toJSONString()); - System.out.println(postRequestConn("http://47.100.55.21:8080/judge",json.toJSONString(),"3c8e8bd79d66259c46d8a3d057278dc8")); - } - - public static String getSHA256Str(String str) { - MessageDigest messageDigest; - String encdeStr = ""; - try { - messageDigest = MessageDigest.getInstance("SHA-256"); - byte[] hash = messageDigest.digest(str.getBytes("UTF-8")); - encdeStr = Hex.encodeHexString(hash); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return encdeStr; - } - - - - /** - * 涓嬭浇浜岀淮鐮佸浘鐗囨枃浠讹紝 - * - * @param urlString - * @return 涓存椂鏂囦欢澶瑰湴鍧� - * @throws Exception - */ - - public static String downloadQrcode(String urlString) throws Exception { - String savePath = System.getProperty("java.io.tmpdir"); - String nfix = ".jpg";// 鏂囦欢鍚庣紑鍚� - String tempName = UUID.randomUUID().toString() + nfix;// 涓存椂鏂囦欢鍚� - - // ----------------鍥剧墖涓嬭浇寮�濮�--------------- - // 鏋勯�燯RL - URL url = new URL(urlString); - // 鎵撳紑杩炴帴 - URLConnection con = url.openConnection(); - // 璁剧疆璇锋眰瓒呮椂涓�5s - con.setConnectTimeout(5 * 1000); - // 杈撳叆娴� - InputStream is = con.getInputStream(); - - // 1K鐨勬暟鎹紦鍐� - byte[] bs = new byte[1024]; - // 璇诲彇鍒扮殑鏁版嵁闀垮害 - int len; - // 杈撳嚭鐨勬枃浠舵祦 - File sf = new File(savePath); - if (!sf.exists()) { - sf.mkdirs(); - } - String tempFilePath = sf.getPath() + "\\" + tempName; - OutputStream os = new FileOutputStream(tempFilePath); - // 寮�濮嬭鍙� - while ((len = is.read(bs)) != -1) { - os.write(bs, 0, len); - } - // 瀹屾瘯锛屽叧闂墍鏈夐摼鎺� - os.close(); - is.close(); - // -------------------鍥剧墖涓嬭浇瀹屾瘯------------------ - - return tempFilePath; - } -} diff --git a/server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java b/server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java index 3de1d47..809e79d 100644 --- a/server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java +++ b/server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java @@ -1,25 +1,16 @@ package com.doumee.core.utils; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; - import javax.net.ssl.*; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URI; +import java.net.HttpURLConnection; import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import java.util.Map; public class HttpsUtil { @@ -30,6 +21,14 @@ public static String post(String url, String data, String contentType, boolean ignoreSSL) { return connection(url, "POST", data, contentType, ignoreSSL); } + public static String postJsonString(String url, String data) { + if(url.startsWith("https://")){ + return connection(url, "POST", data, "application/json", true); + }else{ + return connectionHttp(url, "POST", data, "application/json"); + } + } + public static String connection(String url,String method,String data,String contentType,boolean ignoreSSL){ HttpsURLConnection connection = null; try { @@ -88,6 +87,93 @@ } return null; } + public static InputStream connectionInputsteam(String url,String method,String data,String contentType ){ + HttpURLConnection connection = null; + try { + URL _url = new URL(url); + connection = (HttpURLConnection) _url.openConnection(); + connection.setRequestMethod(method); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(false); + if(contentType != null){ + connection.setRequestProperty("Content-Type", contentType); + } + connection.connect(); + if(data != null){ + OutputStream outputStream = connection.getOutputStream(); + outputStream.write(data.getBytes("utf-8")); + outputStream.close(); + } + int responseCode = connection.getResponseCode(); + if (responseCode == HttpsURLConnection.HTTP_OK) { + return connection.getInputStream(); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if(connection != null){ + connection.disconnect(); + } + } + return null; + } + public static String connectionHttp(String url,String method,String data,String contentType ){ + HttpURLConnection connection = null; + try { + URL _url = new URL(url); + connection = (HttpURLConnection) _url.openConnection(); + connection.setRequestMethod(method); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(false); + if(contentType != null){ + connection.setRequestProperty("Content-Type", contentType); + } + + connection.connect(); + + if(data != null){ + OutputStream outputStream = connection.getOutputStream(); + outputStream.write(data.getBytes("utf-8")); + outputStream.close(); + } + + int responseCode = connection.getResponseCode(); + if (responseCode == HttpsURLConnection.HTTP_OK) { + InputStream is = connection.getInputStream(); + byte[] b = new byte[4096]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(b.length); + int len; + while ((len = is.read(b)) != -1) { + baos.write(b, 0, len); + } + is.close(); + return baos.toString("utf-8"); + } + return connection.getResponseMessage(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if(connection != null){ + connection.disconnect(); + } + } + return null; + } + + + public static void main(String[] args) { + //灞�閮ㄤ俊浠绘墍鏈夎瘉涔﹀拰涓绘満 + String result = HttpsUtil.get("https://127.0.0.1:8443/ssl-test/test01.do",true); + System.out.println(result); + + //澶栭儴淇′换鎵�鏈夎瘉涔﹀拰涓绘満 + HttpsTrustManager.allowAllSSL(); + String response = HttpsUtil.get("https://127.0.0.1:8443/ssl-test/test01.do", false); + System.out.println(result); + + } public static InputStream postJson(String url, String data){ HttpsURLConnection connection = null; try { @@ -125,64 +211,10 @@ e.printStackTrace(); } finally { if(connection != null){ - // connection.disconnect(); + // connection.disconnect(); } } return null; - } - /** - * 鍙戦�乬et璇锋眰 - * @param url 璇锋眰URL - * @param param 璇锋眰鍙傛暟 key:value url鎼哄甫鍙傛暟 鎴栬�呮棤鍙傚彲涓嶅~ - * @return - */ - public static String doGet(String url, Map<String, String> param) { - // 鍒涘缓Httpclient瀵硅薄 - CloseableHttpClient httpclient = HttpClients.createDefault(); - String resultString = ""; - CloseableHttpResponse response = null; - try { - // 鍒涘缓uri - URIBuilder builder = new URIBuilder(url); - if (param != null) { - for (String key : param.keySet()) { - builder.addParameter(key, param.get(key)); - } - } - URI uri = builder.build(); - // 鍒涘缓http GET璇锋眰 - HttpGet httpGet = new HttpGet(uri); - // 鎵ц璇锋眰 - response = httpclient.execute(httpGet); - // 鍒ゆ柇杩斿洖鐘舵�佹槸鍚︿负200 - if (response.getStatusLine().getStatusCode() == 200) { - resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (response != null) { - response.close(); - } - httpclient.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return resultString; - } - - public static void main(String[] args) { - //灞�閮ㄤ俊浠绘墍鏈夎瘉涔﹀拰涓绘満 - String result = HttpsUtil.get("https://127.0.0.1:8443/ssl-test/test01.do",true); - System.out.println(result); - - //澶栭儴淇′换鎵�鏈夎瘉涔﹀拰涓绘満 - HttpsTrustManager.allowAllSSL(); - String response = HttpsUtil.get("https://127.0.0.1:8443/ssl-test/test01.do", false); - System.out.println(result); - } } diff --git a/server/services/src/main/java/com/doumee/core/utils/StringTools.java b/server/services/src/main/java/com/doumee/core/utils/StringTools.java index cc470ac..b10f795 100644 --- a/server/services/src/main/java/com/doumee/core/utils/StringTools.java +++ b/server/services/src/main/java/com/doumee/core/utils/StringTools.java @@ -170,7 +170,7 @@ index++; } String result = str.substring(index); - return str; + return result; } public static int[] toArray(Collection<Integer> list) { diff --git a/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java index 1302e95..c7a2291 100644 --- a/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java +++ b/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java @@ -13,6 +13,8 @@ import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.DateUtil; +import com.doumee.core.utils.HttpsUtil; +import com.doumee.core.utils.StringTools; import com.doumee.core.utils.Utils; import com.doumee.dao.business.ActionLogMapper; import com.doumee.dao.business.BikesMapper; @@ -371,8 +373,33 @@ update.setBackUserid(user.getId()); update.setBackType(Constants.ONE); update.setStatus(Constants.MEMBER_RIDES_STATUS.BACK_CYCLING.getKey()); - update.setBackSiteId(collect.get(Constants.FORCE_BACK_SITE).getCode()); - update.setBackLockId(Constants.formatIntegerFromStr(collect.get(Constants.FORCE_BACK_LOCK).getCode())); + String logInfo = null; + Bikes bike =null; + if(Constants.equalsInteger(model.getType(),Constants.ZERO)){ + //濡傛灉鏄嚜琛岃溅锛岀粦瀹氬埌铏氭嫙绔欑偣鍜岄攣澶� + update.setBackSiteId(collect.get(Constants.FORCE_BACK_SITE).getCode()); + update.setBackLockId(Constants.formatIntegerFromStr(collect.get(Constants.FORCE_BACK_LOCK).getCode())); + //鎻掑叆铏氭嫙閿佸ご鍜岀珯鐐逛笂------- + bike = new Bikes(); + bike.setIsdeleted(Constants.ZERO); + bike.setCode(model.getBikeCode()); + bike.setType(model.getType()); + bike.setSiteId(update.getBackSiteId()); + bike.setLockId(update.getBackLockId()); + if(bikesMapper.selectCount(new QueryWrapper<>(bike)) == 0){ + bike.setId(Constants.getUUID()); + bike.setParamId(model.getParamId()); + bike.setLastBackDate(model.getRentDate()); + bike.setStatus(Constants.ZERO); + bike.setType(Constants.ZERO); + bike.setInfo("寮哄埗杩樿溅缁戝畾"); + bikesMapper.insert(bike); + } + }else{ + //濡傛灉鏄數杞︼紝璇锋眰web绔帴鍙e叧闂溅杈嗕俊鎭� + bike = sendCloseElecBikeRequest(memberRides.getBikeCode(),Constants.ONE); + } + logInfo = bike!=null?bike.getInfo():null; Integer freeRentTime = Integer.valueOf(collect.get(Constants.FREE_RENT_TIME).getCode()); Integer rideTime = DateUtil.betweenMin(model.getRentDate(), update.getBackDate()); //璁$畻楠戣璁¤垂鏃堕暱 @@ -383,23 +410,6 @@ String beforeContent = JSONObject.toJSONString(model); //淇敼鍚� String after = JSONObject.toJSONString(update); - - //鎻掑叆铏氭嫙閿佸ご鍜岀珯鐐逛笂------- - Bikes bike = new Bikes(); - bike.setIsdeleted(Constants.ZERO); - bike.setCode(model.getBikeCode()); - bike.setType(model.getType()); - bike.setSiteId(update.getBackSiteId()); - bike.setLockId(update.getBackLockId()); - if(bikesMapper.selectCount(new QueryWrapper<>(bike)) == 0){ - bike.setId(Constants.getUUID()); - bike.setParamId(model.getParamId()); - bike.setLastBackDate(model.getRentDate()); - bike.setStatus(Constants.ZERO); - bike.setType(Constants.ZERO); - bike.setInfo("寮哄埗杩樿溅缁戝畾"); - bikesMapper.insert(bike); - } ActionLog log = new ActionLog(); log.setId(Constants.getUUID()); @@ -414,6 +424,7 @@ log.setObjType(Constants.ActionLogObjType.memberrides); log.setResult(Constants.ZERO); log.setObjId(model.getId()); + log.setInfo(logInfo); log.setType(Constants.ACTIONLOG_TYPE.FORCE_BACK.getKey()); log.setContent(Constants.ACTIONLOG_TYPE.FORCE_BACK.getInfo()); log.setTitle(Constants.ACTIONLOG_TYPE.FORCE_BACK.getName()); @@ -423,7 +434,52 @@ actionLogMapper.insert(log); } + /** + * 濡傛灉鏄數杞︼紝璇锋眰web绔帴鍙e叧闂溅杈嗕俊鎭� + */ + private Bikes sendCloseElecBikeRequest(String bikeCode,int type) { + Bikes bike = bikesMapper.selectOne(new QueryWrapper<Bikes>().lambda() + .eq(Bikes::getType,Constants.ONE) + .eq(Bikes::getIsdeleted,Constants.ZERO) + .eq(Bikes::getCode,bikeCode) + ); + if(bike == null){ + return null; + } + bike.setInfo("寮哄埗杩樿溅鍏抽棴杞﹂攣澶辫触锛�"); + if(StringUtils.isNotBlank(bike.getDeviceSn())){ + try { + //璇锋眰鍦板潃 + String url = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ELEC_BIKE_CONTRIL_API_URL).getCode(); + JSONObject param = new JSONObject(); + param.put("clientId",StringTools.leftTrip(bike.getDeviceSn(),'0')); + param.put("type",type);//0寮�閿� 1鍏抽攣 + String res = HttpsUtil.postJsonString(url,param.toJSONString()); + JSONObject json = JSONObject.parseObject(res); + if(json.get("code").equals("200")){ + //鍙戣捣鎸囦护鎴愬姛 + bike.setInfo("寮哄埗杩樿溅鍏抽棴杞﹂攣鎴愬姛锛�"); + }else{ + bike.setInfo("寮哄埗杩樿溅鍏抽棴杞﹂攣澶辫触锛�"+json.get("msg")); + } + }catch (Exception e){ + e.printStackTrace(); + } + }else{ + bike.setInfo("寮哄埗杩樿溅鍏抽棴杞﹂攣澶辫触,鏈粦瀹氭帶鍒跺櫒sn锛�"); + } + bikesMapper.updateById(bike); + return bike; + } + public static void main(String[] args) { + String url = "http://localhost:10025/jtt808/device/8500"; + JSONObject param = new JSONObject(); + param.put("clientId",StringTools.leftTrip("0067244400211",'0')); + param.put("type",0);//0寮�閿� 1鍏抽攣 + String res = HttpsUtil.postJsonString(url,param.toJSONString()); + System.out.println(res); + } public ConcurrentMap<String,Integer> cacheOpenLock = new ConcurrentReferenceHashMap<>(); @Override diff --git a/server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java b/server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java index 81510a2..b22e0eb 100644 --- a/server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java +++ b/server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java @@ -177,7 +177,7 @@ private void lockBikes(String clientId,int type) { T8500 request = new T8500(); request.setType(type);//鍏抽攣 - request.setClientId(StringTools.leftPad(clientId,12,'0')); + request.setClientId(StringTools.leftTrip(clientId,'0')); Mono<APIResult<T0201_0500>> result = messageManager.requestR(request, T0201_0500.class); APIResult<T0201_0500> data = result.block(); if(!data.isSuccess()){ -- Gitblit v1.9.3