Browse Source

调整云快充

liuf 6 months atrás
parent
commit
9a95502350

+ 1 - 1
readme.txt

@@ -16,4 +16,4 @@ docker stop device-link-ykc
 docker rm device-link-ykc
 docker rmi device-link-ykc
 
-docker-compose up -d --build device-link-ykc
+

+ 4 - 2
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -48,6 +48,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 /**
@@ -104,9 +105,10 @@ public class TestController {
             //查询所有充电中设备的最新的订单记录,来上报设备状态消息.........?????????????????
             OrderStatus orderStatus = orderStatusService.getOne(queryWrapper);
 
-            Map<String, BigDecimal> map = transMoney.compute(orderStatus.getGunsCode(), b, orderStatus.getCreateTime(), orderStatus.getEndTime());
+            Map<String, BigDecimal> map = transMoney.compute(orderStatus.getGunsCode(), b, orderStatus.getCreateTime(), orderStatus.getEndTime(),orderStatus);
+            logger.info(orderStatus.getPileCode() + "计算电费,{},{}," + DataConversion.bytesToHexString(orderStatus.getTransOrder()),map.get("money"),map.get("elec"));
 
-           byte[] params = transactionFlowPushFrame.params16(orderStatus.getTransOrder(), pileCode, orderStatus.getGunsCode(),
+            byte[] params = transactionFlowPushFrame.params16(orderStatus.getTransOrder(), pileCode, orderStatus.getGunsCode(),
                    orderStatus.getCreateTime(), orderStatus.getEndTime(), b, orderStatus.getCard(), map,0);
             //deviceMsgHandle.testMsg(message);
 

+ 46 - 489
src/main/java/com/tmzn/devicelinkykc/frameMsg/TransMoney.java

@@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse;
 import com.alibaba.fastjson2.JSONObject;
 import com.tmzn.devicelinkykc.constant.ykc.BillingModelConst;
 import com.tmzn.devicelinkykc.entity.BillingModel;
+import com.tmzn.devicelinkykc.entity.OrderStatus;
 import com.tmzn.devicelinkykc.entity.param.dto.BillingModelDTO;
 import com.tmzn.devicelinkykc.mapstruct.BillingModelMapping;
 import lombok.extern.slf4j.Slf4j;
@@ -20,6 +21,7 @@ import java.time.temporal.ChronoUnit;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -40,20 +42,21 @@ public class TransMoney {
     private BillingModelMapping billingModelMapping;
 
     public Map<String,BigDecimal> getTransData(){
-        BigDecimal bigDecimal = new BigDecimal("0.0000");
-        Map<String, BigDecimal> transData = new HashMap<>();
-        transData.put("elec",bigDecimal);
-        transData.put("elec1",bigDecimal);
-        transData.put("elec2",bigDecimal);
-        transData.put("elec3",bigDecimal);
-        transData.put("elec4",bigDecimal);
-        transData.put("elec5",bigDecimal);
-        transData.put("money",bigDecimal);
-        transData.put("money1",bigDecimal);
-        transData.put("money2",bigDecimal);
-        transData.put("money3",bigDecimal);
-        transData.put("money4",bigDecimal);
-        transData.put("money5",bigDecimal);
+//        BigDecimal bigDecimal = new BigDecimal("0.0000");
+        Map<String, BigDecimal> transData = new ConcurrentHashMap<>();
+        transData.put("elec",new BigDecimal("0.0000"));
+        transData.put("elec1",new BigDecimal("0.0000"));
+        transData.put("elec2",new BigDecimal("0.0000"));
+        transData.put("elec3",new BigDecimal("0.0000"));
+        transData.put("elec4",new BigDecimal("0.0000"));
+        transData.put("elec5",new BigDecimal("0.0000"));
+        transData.put("money",new BigDecimal("0.0000"));
+        transData.put("money1",new BigDecimal("0.0000"));
+        transData.put("money2",new BigDecimal("0.0000"));
+        transData.put("money3",new BigDecimal("0.0000"));
+        transData.put("money4",new BigDecimal("0.0000"));
+        transData.put("money5",new BigDecimal("0.0000"));
+
         return transData;
     }
 
@@ -65,25 +68,39 @@ public class TransMoney {
      * @param endTime
      * @return
      */
-    public Map<String,BigDecimal> compute(int port,BillingModel billingModel,Long startTime,Long endTime) throws Exception{
-
-        Map<String,BigDecimal> transData = getTransData();
-        try {
-            TimeUnit.MILLISECONDS.sleep(1000);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        HashMap<String, Object> map = new HashMap<>();
+    public Map<String,BigDecimal> compute(int port, BillingModel billingModel, Long startTime, Long endTime, OrderStatus orderStatus) throws Exception{
+
+//        Map<String, BigDecimal> transData = getTransData();
+        Map<String, BigDecimal> transData = new ConcurrentHashMap<>();
+        transData.put("elec",new BigDecimal("0.0000"));
+        transData.put("elec1",new BigDecimal("0.0000"));
+        transData.put("elec2",new BigDecimal("0.0000"));
+        transData.put("elec3",new BigDecimal("0.0000"));
+        transData.put("elec4",new BigDecimal("0.0000"));
+        transData.put("elec5",new BigDecimal("0.0000"));
+        transData.put("money",new BigDecimal("0.0000"));
+        transData.put("money1",new BigDecimal("0.0000"));
+        transData.put("money2",new BigDecimal("0.0000"));
+        transData.put("money3",new BigDecimal("0.0000"));
+        transData.put("money4",new BigDecimal("0.0000"));
+        transData.put("money5",new BigDecimal("0.0000"));
+//        try {
+//          //  TimeUnit.MILLISECONDS.sleep(1000);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+        HashMap<String, Object> bparam = new HashMap<>();
         BillingModelDTO billingModelDTO = billingModelMapping.billingModelToBillingModelDto(billingModel);
-        map.put("port",port);
-        map.put("billingModel",billingModelDTO);
+        bparam.put("port",port);
+        bparam.put("billingModel",billingModelDTO);
         //为了防止落库时间差
-        map.put("startTime",(startTime-5*1000)/1000);
-        map.put("endTime",(endTime+5*1000)/1000);
-        JSONObject jsonObject = new JSONObject(map);
+        bparam.put("startTime",(startTime-5*1000)/1000);
+        bparam.put("endTime",(endTime+5*1000)/1000);
+        bparam.put("order_id",orderStatus.getId());
+        JSONObject jsonObject = new JSONObject(bparam);
         String s = jsonObject.toString();
 //        String billUrl = "http://wetiandi.com/app/index.php?i=1&j=1&c=auth&a=calculate_cost_new&do=compute_elec_all";
-        log.info("后台计费请求参数>>>>{}"+s,url);
+        log.info("后台计费请求参数>>>>{},{}"+s,url,orderStatus.getId());
         //String url = "http://your-api-url.com/post";
 //        og.info("后台计费请求参数>>>>"+json);
         //final String url = "http://your-api-url.com/post"; // 替换成您的API URL
@@ -160,472 +177,12 @@ public class TransMoney {
         } catch (IOException e) {
             e.printStackTrace();
         }
-
-//        HttpResponse execute = HttpRequest.post(url).form("data",s).timeout(10000).execute();
-//        int status = execute.getStatus();
-//        log.info("HttpResponse>>>>"+execute.toString());
-////        System.out.println(execute.toString());
-////        System.out.println("status>>>"+status);
-//        if (status==200){
-//            try {
-//
-//                String body = execute.body();
-//                if (null==body||"".equals(body)){
-//                    log.info("后台响应body-null>>>"+body);
-//                    return transData;
-//                }
-//                log.info("body>>>"+body);
-//                JSONObject parseObject = JSONObject.parseObject(body);
-//                //log.info("后台计费响应参数>>>>"+parseObject.toString());
-//                boolean rv1 = parseObject.containsKey("rv");
-//                if (!rv1){
-//                    log.info("rv>>>not found>transData:0");
-//                    return transData;
-//                }
-//                Integer rv = parseObject.getInteger("rv");
-//                if (rv==1){
-//                    //返回正确,PHP端防止精度丢失全部采用整数发送 需要保留四位小数 除以10000
-//                    BigDecimal precise = new BigDecimal(10000);  //1000模拟大电流充电
-//                    JSONObject parseObjectJSONObject = parseObject.getJSONObject("elec_map");
-//                    transData.put("elec",parseObjectJSONObject.getBigDecimal("elec").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("elec1",parseObjectJSONObject.getBigDecimal("elec1").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("elec2",parseObjectJSONObject.getBigDecimal("elec2").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("elec3",parseObjectJSONObject.getBigDecimal("elec3").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("elec4",parseObjectJSONObject.getBigDecimal("elec4").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("money",parseObjectJSONObject.getBigDecimal("money").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("money1",parseObjectJSONObject.getBigDecimal("money1").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("money2",parseObjectJSONObject.getBigDecimal("money2").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("money3",parseObjectJSONObject.getBigDecimal("money3").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    transData.put("money4",parseObjectJSONObject.getBigDecimal("money4").divide(precise,4,BigDecimal.ROUND_DOWN));
-//                    return transData;
-//                }
-//            }catch (Exception e){
-//                log.info("计费处理异常>>"+e);
-//                e.printStackTrace();
-//            }
-//
-//        }
-
         return transData;
     }
 
 
 
 
-    /**
-     * 测试一个时间段的计费
-     *
-     * @param model
-     * @param startTime
-     * @param endTime
-     * @param elecAll
-     * @return
-     */
-    public static Map<String, BigDecimal> startElec(BillingModel model, Long startTime, Long endTime, BigDecimal elecAll)  throws Exception{
-        //elecAll = new BigDecimal("3.5");
-        BigDecimal star = new BigDecimal(startTime);
-        BigDecimal end = new BigDecimal(endTime);
-        BigDecimal time = (end.subtract(star)).divide(new BigDecimal(1000 * 60 * 60), 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-        BigDecimal elec = time.multiply(elecAll).setScale(4, BigDecimal.ROUND_DOWN);
-        BigDecimal money = elec.multiply(model.getSharpPrice().add(model.getSharpServiceFee())).setScale(4, BigDecimal.ROUND_DOWN);
-
-
-        BigDecimal init = new BigDecimal(0);
-        Map<String, BigDecimal> transData = new HashMap<>();
-        transData.put("money", money);
-        transData.put("elec", elec);
-        transData.put("money1", money);
-        transData.put("money2", init);
-        transData.put("money3", init);
-        transData.put("money4", init);
-        transData.put("elec1", elec);
-        transData.put("elec2", init);
-        transData.put("elec3", init);
-        transData.put("elec4", init);
-        log.info("测试计费map>>>");
-        transData.keySet().stream().forEach(s -> log.info(s + ":" + transData.get(s)));
-        return transData;
-    }
-
-
-    /**
-     * 功率计算费用
-     *
-     * @param power
-     * @param billingModel
-     * @param startTimeMillis
-     * @param endTime
-     * @return
-     */
-    public Map<String, BigDecimal> start(Integer power, BillingModel billingModel, Long startTimeMillis, Long endTime)  throws Exception{
-        Date startDate = new Date(startTimeMillis);
-        Date endDate = new Date(endTime);
-        log.info("startTime:"+startDate+";endTime:"+endDate);
-        BigDecimal init = new BigDecimal(0);
-        Map<String,BigDecimal> transData = getTransData();
-        transData.put("money1", init);
-        transData.put("money2", init);
-        transData.put("money3", init);
-        transData.put("money4", init);
-        transData.put("elec1", init);
-        transData.put("elec2", init);
-        transData.put("elec3", init);
-        transData.put("elec4", init);
-        BigDecimal powerInt = new BigDecimal(power);
-        String str = billingModel.getTimeSlot();
-        String[] model = str.split("");
-        long nowTimeMillis = 0L;
-        if (endTime == 0) {
-            nowTimeMillis = System.currentTimeMillis();
-        } else {
-            nowTimeMillis = endTime;
-        }
 
-        //开始
-        LocalDateTime startDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(startTimeMillis), java.time.ZoneId.systemDefault());
-        LocalDate starlocalDate = Instant.ofEpochMilli(startTimeMillis).atZone(ZoneId.systemDefault()).toLocalDate();
-        int startHour = startDateTime.getHour();
-        int startMinute = startDateTime.getMinute();
-        LocalTime startTime = LocalTime.of(startHour, startMinute);
 
-        //现在
-        LocalDateTime nowDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(nowTimeMillis), java.time.ZoneId.systemDefault());
-        LocalDate nowlocalDate = Instant.ofEpochMilli(nowTimeMillis).atZone(ZoneId.systemDefault()).toLocalDate();
-        int nowHour = nowDateTime.getHour();
-        int nowMinute = nowDateTime.getMinute();
-        LocalTime nowTime = LocalTime.of(nowHour, nowMinute);
-
-        //开始时间点在的半小时时间段
-        int startTimeSlot = startTime.toSecondOfDay() / 1800;
-        String ss = model[startTimeSlot];
-        byte startTimePirce = Byte.parseByte(ss);
-
-        //结束时间点在的半小时时间段
-        int nowTimeSlot = nowTime.toSecondOfDay() / 1800;
-        String ns = model[nowTimeSlot];
-        byte nowTimePirce = Byte.parseByte(ns);
-
-
-        //当前时间和开始充电时间相差天数,防止跨天充电
-        long until = starlocalDate.until(nowlocalDate, ChronoUnit.DAYS);
-        //BigDecimal money = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-        Map<String, BigDecimal> map = new HashMap<>();
-        if (until < 1) {
-            //相差0,同一天的充电
-            log.info("交易记录:同一天的充电,数据计算>>>>");
-            map = onDayMoney(powerInt, billingModel, startTimeMillis, nowTimeMillis);
-            //money = money.add(onDayMoney(powerInt, billingModel, startTimeMillis, nowTimeMillis));
-
-        } else if (until == 1) {
-            //跨一天 开始时间到晚上24:00  24:00到结束时间
-            log.info("交易记录:跨一天的充电,数据计算>>>>");
-            map = differentDayMoney(powerInt, billingModel, startTimeMillis, nowTimeMillis);
-        } else {
-            //跨多天
-            log.info("交易记录:跨多天的充电,数据计算>>>>");
-            Map<String, BigDecimal> mapall = allDayMoney(powerInt, billingModel);
-            map = differentDayMoney(powerInt, billingModel, startTimeMillis, nowTimeMillis);
-
-            BigDecimal elecAll = mapall.get("elec");
-            BigDecimal moneyAll = mapall.get("money");
-
-            BigDecimal elecDiff = map.get("elec");
-            BigDecimal moneyDiff = map.get("money");
-
-            BigDecimal elec = elecDiff.add(elecAll.multiply(new BigDecimal(until - 1L)).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal money = moneyDiff.add(moneyAll.multiply(new BigDecimal(until - 1L)).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-            map.put("elec", elec);
-            map.put("money", money);
-        }
-        transData.put("elec", map.get("elec"));
-        transData.put("money", map.get("money"));
-
-        Map<String, BigDecimal> finaltransData = transData;
-        finaltransData.keySet().stream().forEach(s -> {
-            log.info(s + ":" + finaltransData.get(s));
-        });
-        return transData;
-    }
-
-    /**
-     * 跨整天的费用数据
-     *
-     * @param power
-     * @param billingModel
-     * @return
-     */
-    private Map<String, BigDecimal> allDayMoney(BigDecimal power, BillingModel billingModel)  throws Exception{
-        BigDecimal money = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-        BigDecimal elec = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-        String str = billingModel.getTimeSlot();
-        String[] model = str.split("");
-        for (String s : model) {
-            byte b = Byte.parseByte(s);
-            money = money.add(money(b, new BigDecimal(30), power, billingModel));
-            BigDecimal chargTime = new BigDecimal(30).divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(chargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-        }
-        Map<String, BigDecimal> decimalHashMap = new HashMap<>();
-        decimalHashMap.put("money", money);
-        decimalHashMap.put("elec", elec);
-        return decimalHashMap;
-    }
-
-    /**
-     * 跨天数的费率计算
-     *
-     * @param power
-     * @param billingModel
-     * @param startTimeMillis
-     * @param nowTimeMillis
-     * @return
-     */
-    private Map<String, BigDecimal> differentDayMoney(BigDecimal power, BillingModel billingModel, Long startTimeMillis, Long nowTimeMillis) throws Exception {
-        BigDecimal money = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-        BigDecimal elec = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-        String str = billingModel.getTimeSlot();
-        String[] model = str.split("");
-
-        //开始
-        LocalDateTime startDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(startTimeMillis), java.time.ZoneId.systemDefault());
-        LocalDate starlocalDate = Instant.ofEpochMilli(startTimeMillis).atZone(ZoneId.systemDefault()).toLocalDate();
-        int startHour = startDateTime.getHour();
-        int startMinute = startDateTime.getMinute();
-        int startSecond = startDateTime.getSecond();
-        LocalTime startTime = LocalTime.of(startHour, startMinute);
-
-        //现在
-        LocalDateTime nowDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(nowTimeMillis), java.time.ZoneId.systemDefault());
-        LocalDate nowlocalDate = Instant.ofEpochMilli(nowTimeMillis).atZone(ZoneId.systemDefault()).toLocalDate();
-        int nowHour = nowDateTime.getHour();
-        int nowMinute = nowDateTime.getMinute();
-        int nowSecond = nowDateTime.getSecond();
-        LocalTime nowTime = LocalTime.of(nowHour, nowMinute);
-
-        //开始时间点在的半小时时间段
-        int startTimeSlot = startTime.toSecondOfDay() / 1800;
-        String ss = model[startTimeSlot];
-        byte startTimePirce = Byte.parseByte(ss);
-
-        //结束时间点在的半小时时间段
-        int nowTimeSlot = nowTime.toSecondOfDay() / 1800;
-        String ns = model[nowTimeSlot];
-        byte nowTimePirce = Byte.parseByte(ns);
-
-        if (startTimeSlot == 47) {
-            //特殊情况:开始时间段就在最后半小时实际那段,没有24:00 的时间,只能单独计算费用
-            BigDecimal bigDecimal = new BigDecimal(24 * 60 * 60 - (startHour * 60 * 60 + startMinute * 60 + startSecond));
-            BigDecimal time = bigDecimal.divide(hourToMin, 2, BigDecimal.ROUND_DOWN);
-            money = money.add(money(startTimePirce, time, power, billingModel));
-            BigDecimal startchargTime = time.divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(startchargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-        }
-        //47段不会进这个循环
-        for (int i = startTimeSlot + 1; i <= 47; i++) {
-            byte b = Byte.parseByte(model[i]);
-            money = money.add(money(b, new BigDecimal(30), power, billingModel));
-            BigDecimal chargTime = new BigDecimal(30).divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(chargTime.divide(hourToMin,2,BigDecimal.ROUND_DOWN).multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-        }
-        //计算00:00到当前时间的费用
-        //计算当前半小时段内充的电费
-        BigDecimal bigDecimal = new BigDecimal((nowHour * 60 * 60 + nowMinute * 60 + nowSecond) - (nowTimeSlot) * 30 * 60);
-        BigDecimal time = bigDecimal.divide(hourToMin, 2, BigDecimal.ROUND_DOWN);
-        money = money.add(money(nowTimePirce, time, power, billingModel));
-        BigDecimal nowchargTime = time.divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-        elec = elec.add(nowchargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-
-        //当前第一段时不会进循环
-        for (int i = 0; i < nowTimeSlot; i++) {
-            byte b = Byte.parseByte(model[i]);
-            money = money.add(money(b, new BigDecimal(30), power, billingModel));
-            BigDecimal chargTime = new BigDecimal(30).divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(chargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-        }
-        Map<String, BigDecimal> decimalHashMap = new HashMap<>();
-        decimalHashMap.put("money", money);
-        decimalHashMap.put("elec", elec);
-        return decimalHashMap;
-    }
-
-    /**
-     * 同一天的费率计算
-     *
-     * @param power
-     * @param billingModel
-     * @param startTimeMillis
-     * @param nowTimeMillis
-     * @return
-     */
-    private Map<String, BigDecimal> onDayMoney(BigDecimal power, BillingModel billingModel, Long startTimeMillis, Long nowTimeMillis)  throws Exception{
-        String str = billingModel.getTimeSlot();
-        String[] model = str.split("");
-        //时间段的模型
-        //String[] model = billingModel.getTimeSlot().split("");
-        LocalDateTime startDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(startTimeMillis), java.time.ZoneId.systemDefault());
-        // 获取日,小时和分钟
-        //int
-        int startHour = startDateTime.getHour();
-        int startMinute = startDateTime.getMinute();
-        int startSecond = startDateTime.getSecond();
-
-        // 当前时间戳创建LocalDateTime对象
-        LocalDateTime nowDateTime = LocalDateTime.ofInstant(java.time.Instant.ofEpochMilli(nowTimeMillis), java.time.ZoneId.systemDefault());
-        // 获取小时和分钟
-        int nowHour = nowDateTime.getHour();
-        int nowMinute = nowDateTime.getMinute();
-        int nowSecond = nowDateTime.getSecond();
-        //开始时间点
-        LocalTime startTime = LocalTime.of(startHour, startMinute);
-        //当前时间点
-        LocalTime nowTime = LocalTime.of(nowHour, nowMinute);
-        //开始时间点在的半小时时间段
-        int startTimeSlot = startTime.toSecondOfDay() / 1800;
-        String ss = model[startTimeSlot];
-        byte startTimePirce = Byte.parseByte(ss);
-
-        //结束时间点在的半小时时间段
-        int nowTimeSlot = nowTime.toSecondOfDay() / 1800;
-        String ns = model[nowTimeSlot];
-        byte nowTimePirce = Byte.parseByte(ns);
-
-        BigDecimal money = new BigDecimal(0);
-        BigDecimal elec = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-        if (startTimeSlot != nowTimeSlot) {
-            //1111.算出,同一天跨时段充电 电费
-            //启充时间到现在夸多个时段 19  31
-            for (int i = startTimeSlot + 1; i <= nowTimeSlot - 1; i++) {
-                byte b = Byte.parseByte(model[i]);
-                BigDecimal startchargTime = new BigDecimal(30).divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-                money = money.add(money(b, startchargTime, power, billingModel));
-                elec = elec.add(startchargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-            }
-            //开始段费率计算
-            BigDecimal start = new BigDecimal((startTimeSlot + 1) * 30 * 60 - (startHour * 60 * 60 + startMinute * 60 + startSecond));
-            BigDecimal startBigDecimal = start.divide(hourToMin, 2, BigDecimal.ROUND_DOWN);
-            money = money.add(money(startTimePirce, startBigDecimal, power, billingModel));
-            BigDecimal startchargTime = startBigDecimal.divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(startchargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-            //结束段费率计算
-            BigDecimal now = new BigDecimal((nowHour * 60 * 60 + nowMinute * 60 + nowSecond) - nowTimeSlot * 30 * 60);
-            BigDecimal nowBigDecimal = now.divide(hourToMin, 2, BigDecimal.ROUND_DOWN);
-            money = money.add(money(nowTimePirce, nowBigDecimal, power, billingModel));
-            BigDecimal nowchargTime = nowBigDecimal.divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(nowchargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-        } else {
-            //2222.算出同一天的不跨时段充电的电费
-            BigDecimal charging = new BigDecimal((nowMinute * 60 + nowSecond) - (startMinute * 60 + startSecond)).setScale(0);
-            BigDecimal chargingTime = charging.divide(hourToMin, 2, BigDecimal.ROUND_DOWN);
-            //money=money(nowTimePirce,chargingTime,power);一样的计费还在同一个费率段内
-            money = money.add(money(startTimePirce, chargingTime, power, billingModel));
-            BigDecimal chargTime = chargingTime.divide(hourToMin, 4, BigDecimal.ROUND_DOWN).setScale(4, BigDecimal.ROUND_DOWN);
-            elec = elec.add(chargTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN)).setScale(4, BigDecimal.ROUND_DOWN);
-        }
-
-        Map<String, BigDecimal> decimalHashMap = new HashMap<>();
-        decimalHashMap.put("money", money);  //总金额
-        decimalHashMap.put("elec", elec);     //总电量
-        return decimalHashMap;
-    }
-
-    /**
-     * @param b            模型
-     * @param chargingTime 充电时间
-     * @param power        功率
-     * @return
-     */
-    private BigDecimal money(byte b, BigDecimal chargingTime, BigDecimal power, BillingModel billingModel)  throws Exception{
-        //电价  段电价+服务费
-        Map<String,BigDecimal> transData = getTransData();
-        BigDecimal sharpPrice = billingModel.getSharpPrice().add(billingModel.getSharpServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);
-        BigDecimal peakPrice = billingModel.getPeakPrice().add(billingModel.getPeakServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);
-        BigDecimal flatPrice = billingModel.getFlatPrice().add(billingModel.getFlatServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);
-        BigDecimal valleyPrice = billingModel.getValleyPrice().add(billingModel.getValleyServiceFee()).setScale(5, BigDecimal.ROUND_DOWN);
-        BigDecimal money = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-
-        BigDecimal bigDecimal = new BigDecimal(60);
-        BigDecimal divideTime = chargingTime.divide(bigDecimal, 4, BigDecimal.ROUND_DOWN);
-
-        BigDecimal elec = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-
-
-        if (b == BillingModelConst.SHARP) {
-            //段计费
-            money = divideTime.multiply(sharpPrice).multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal money1 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("money1")) {
-                money1 = transData.get("money1");
-            }
-            money1 = money1.add(money).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("money1", money1);
-
-            //段电量
-            elec = divideTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal elec1 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("elec1")) {
-                elec1 = transData.get("elec1");
-            }
-            elec1 = elec1.add(elec).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("elec1", elec1);
-
-        } else if (b == BillingModelConst.PEAK) {
-            //段计费
-            money = divideTime.multiply(peakPrice).multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal money2 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("money2")) {
-                money2 = transData.get("money2");
-            }
-            money2 = money2.add(money).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("money2", money2);
-
-            //段电量
-            elec = divideTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal elec2 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("elec2")) {
-                elec2 = transData.get("elec2");
-            }
-            elec2 = elec2.add(elec).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("elec2", elec2);
-
-        } else if (b == BillingModelConst.FLAT) {
-            //段计费
-            money = divideTime.multiply(flatPrice).multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal money3 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("money3")) {
-                money3 = transData.get("money3");
-            }
-            money3 = money3.add(money).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("money3", money3);
-
-            //段电量
-            elec = divideTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal elec3 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("elec3")) {
-                elec3 = transData.get("elec3");
-            }
-            elec3 = elec3.add(elec).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("elec3", elec3);
-
-        } else if (b == BillingModelConst.VALLEY) {
-            //段计费
-            money = divideTime.multiply(valleyPrice).multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal money4 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("money4")) {
-                money4 = transData.get("money4");
-            }
-            money4 = money4.add(money).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("money4", money4);
-
-            //段电量
-            elec = divideTime.multiply(power).setScale(4, BigDecimal.ROUND_DOWN);
-            BigDecimal elec4 = new BigDecimal(0).setScale(4, BigDecimal.ROUND_DOWN);
-            if (transData.containsKey("elec4")) {
-                elec4 = transData.get("elec4");
-            }
-            elec4 = elec4.add(elec).setScale(4, BigDecimal.ROUND_DOWN);
-            transData.put("elec4", elec4);
-
-        }
-        return money;
-    }
 }

+ 1 - 0
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/TransactionFlowPushFrame.java

@@ -74,6 +74,7 @@ public class TransactionFlowPushFrame {
 
 
     public byte[] sendTrans(DeviceConnectionMsg deviceConnectionMsg,byte[] transOrder, String pileCode, byte gunPort, long createTime, long endTime, BillingModel billingModel, byte[] card, Map<String, BigDecimal> map,int reason)  {
+        log.info("sendTrans订单金额:{},{},{}",pileCode,map.get("money"),map.get("elec"));
         if(deviceConnectionMsg.getIs18()){
             byte[] encrypt = new byte[0];
             // 缓存上报的订单,上报失败30秒重试,

+ 3 - 2
src/main/java/com/tmzn/devicelinkykc/message/DeviceMsgHandle.java

@@ -39,6 +39,7 @@ import org.springframework.stereotype.Controller;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 
 
@@ -703,8 +704,8 @@ public class DeviceMsgHandle {
             QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
             billingModelQueryWrapper.eq("device_imei", imei);
             BillingModel model = billingModelService.getOne(billingModelQueryWrapper);
-            Map<String, BigDecimal> map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime());
-            logger.info(statusServiceOne.getPileCode() + "计算电费" + DataConversion.bytesToHexString(statusServiceOne.getTransOrder()));
+            Map<String, BigDecimal> map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(),statusServiceOne);
+            logger.info(statusServiceOne.getPileCode() + "计算电费,{},{}" + DataConversion.bytesToHexString(statusServiceOne.getTransOrder()),map.get("money"),map.get("elec"));
             encrypt = transactionFlowPushFrame.sendTrans(deviceConnection, statusServiceOne.getTransOrder(), statusServiceOne.getPileCode(), statusServiceOne.getGunsCode(), statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(), model, statusServiceOne.getCard(), map, statusServiceOne.getReasonStopCharging());
 
             if (encrypt == null || encrypt.length <= 0) {

+ 7 - 3
src/main/java/com/tmzn/devicelinkykc/message/YkcMsgHandle.java

@@ -38,6 +38,7 @@ import org.springframework.stereotype.Component;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -133,7 +134,9 @@ public class YkcMsgHandle {
                 //消息体
                 byte[] respone_msg = Arrays.copyOfRange(response, 6, response.length - 2);
                 if (encry == 0) {
-                    logger.info("{},un_encry_msg,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(respone_msg));
+                    if(framType!=4){
+                        logger.info("{},un_encry_msg,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(response));
+                    }
                 } else {
                     try {
                         String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
@@ -364,7 +367,8 @@ public class YkcMsgHandle {
         //计算实时数据
         long endTime = System.currentTimeMillis();
         //算电量
-        Map<String, BigDecimal> start = transMoney.getTransData();
+        Map<String, BigDecimal> start =  new ConcurrentHashMap<>();
+
 
         String transCacheKey = "ChargingTrans:"+orderStatus.getId();
         if(redisCache.hasKey(transCacheKey)){
@@ -375,7 +379,7 @@ public class YkcMsgHandle {
                 QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
                 billWapper.in("pile_code", pileCode);
                 BillingModel billingModel = billingModelService.getOne(billWapper);
-                start = transMoney.compute(port, billingModel, orderStatus.getCreateTime(), endTime);
+                start =  transMoney.compute(port, billingModel, orderStatus.getCreateTime(), endTime,orderStatus);
             } catch (Exception e) {
                 e.printStackTrace();
                 logger.error("计算订单异常{},{}",orderStatus.getPileCode(),e.getMessage());

+ 2 - 2
src/main/java/com/tmzn/devicelinkykc/taskQueue/runner/MsgCharngingRunner.java

@@ -262,7 +262,7 @@ public class MsgCharngingRunner {
         //计算实时数据
         long endTime = System.currentTimeMillis();
         //算电量
-        Map<String, BigDecimal> start = transMoney.getTransData();
+        Map<String, BigDecimal> start;
 
         String transCacheKey = "ChargingTrans:"+orderStatus.getId();
         if(redisCache.hasKey(transCacheKey)){
@@ -270,7 +270,7 @@ public class MsgCharngingRunner {
         }else{
             //缓存120秒避免重复计算电量
             try {
-                start = transMoney.compute(port, billingModel, orderStatus.getCreateTime(), endTime);
+                start = transMoney.compute(port, billingModel, orderStatus.getCreateTime(), endTime,orderStatus);
             } catch (Exception e) {
                 e.printStackTrace();
                 log.error("计算订单异常{},{}",orderStatus.getPileCode(),e.getMessage());

+ 1 - 1
src/main/java/com/tmzn/devicelinkykc/taskQueue/runner/MsgTranscationRunner.java

@@ -105,7 +105,7 @@ public class MsgTranscationRunner {
             log.info("{}从缓存获取map{}",statusServiceOne.getDeviceImei(), JSON.toJSONString(map));
         }else{
             try{
-                map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime());
+                map = transMoney.compute(port, model, statusServiceOne.getCreateTime(), statusServiceOne.getEndTime(),statusServiceOne);
                 //10分钟内只查询一次
                 log.info("{}重新获取map{}",statusServiceOne.getDeviceImei(), JSON.toJSONString(map));
                 redisCache.setCacheObject(cacheKey,map);