jiangping
2025-02-19 3e242903008f50818729fe17a4fa38e0b1f02551
jtt808初始化
已删除1个文件
已修改5个文件
601 ■■■■ 文件已修改
server/services/src/main/java/com/doumee/core/constants/Constants.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/utils/HttpUtil.java 356 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/utils/HttpsUtil.java 160 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/core/utils/StringTools.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java 80 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/web/src/main/java/com/doumee/jtt808/web/service/Jtt808Service.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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";
    //车辆类型数据
server/services/src/main/java/com/doumee/core/utils/HttpUtil.java
ÎļþÒÑɾ³ý
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 {
@@ -129,60 +215,6 @@
            }
        }
        return null;
    }
    /**
     * å‘送get请求
     * @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);
    }
}
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) {
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,21 +373,14 @@
        update.setBackUserid(user.getId());
        update.setBackType(Constants.ONE);
        update.setStatus(Constants.MEMBER_RIDES_STATUS.BACK_CYCLING.getKey());
        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()));
        Integer freeRentTime = Integer.valueOf(collect.get(Constants.FREE_RENT_TIME).getCode());
        Integer rideTime = DateUtil.betweenMin(model.getRentDate(), update.getBackDate());
        //计算骑行计费时长
        update.setDuration( rideTime > freeRentTime  ? rideTime : 0 );
        //update.setDuration( freeRentTime > 0 ? rideTime - freeRentTime : rideTime);
        memberRidesMapper.updateById(update);
        //修改前
        String beforeContent = JSONObject.toJSONString(model);
        //修改后
        String after = JSONObject.toJSONString(update);
        //插入虚拟锁头和站点上-------
        Bikes bike = new Bikes();
            bike = new Bikes();
        bike.setIsdeleted(Constants.ZERO);
        bike.setCode(model.getBikeCode());
        bike.setType(model.getType());
@@ -400,6 +395,21 @@
            bike.setInfo("强制还车绑定");
            bikesMapper.insert(bike);
        }
        }else{
            //如果是电车,请求web端接口关闭车辆信息
            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());
        //计算骑行计费时长
        update.setDuration( rideTime > freeRentTime  ? rideTime : 0 );
        //update.setDuration( freeRentTime > 0 ? rideTime - freeRentTime : rideTime);
        memberRidesMapper.updateById(update);
        //修改前
        String beforeContent = JSONObject.toJSONString(model);
        //修改后
        String after = JSONObject.toJSONString(update);
        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端接口关闭车辆信息
     */
    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
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()){