| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- package com.tmzn.devicelinkykc.controller;
- import cn.hutool.http.HttpRequest;
- import cn.hutool.http.HttpResponse;
- import com.alibaba.fastjson2.JSONArray;
- import com.alibaba.fastjson2.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
- import com.tmzn.devicelinkykc.entity.BillingModel;
- import com.tmzn.devicelinkykc.entity.Device;
- import com.tmzn.devicelinkykc.entity.DeviceStatus;
- import com.tmzn.devicelinkykc.entity.OrderStatus;
- import com.tmzn.devicelinkykc.entity.param.AjaxResult;
- import com.tmzn.devicelinkykc.entity.param.dto.BillingModelDTO;
- import com.tmzn.devicelinkykc.frameMsg.DataConversion;
- import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
- import com.tmzn.devicelinkykc.frameMsg.TransMoney;
- import com.tmzn.devicelinkykc.frameMsg.frameType.LoginFrame;
- import com.tmzn.devicelinkykc.frameMsg.frameType.RealTimeStatusPushFrame;
- import com.tmzn.devicelinkykc.frameMsg.frameType.TransactionFlowPushFrame;
- import com.tmzn.devicelinkykc.mapstruct.BillingModelMapping;
- import com.tmzn.devicelinkykc.message.DeviceMsgHandle;
- import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
- import com.tmzn.devicelinkykc.redis.RedisCache;
- import com.tmzn.devicelinkykc.service.BillingModelService;
- import com.tmzn.devicelinkykc.service.DeviceControlerService;
- import com.tmzn.devicelinkykc.service.DeviceStatusService;
- import com.tmzn.devicelinkykc.service.OrderStatusService;
- import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
- import com.tmzn.devicelinkykc.transdata.entity.DeviceParam;
- import com.tmzn.devicelinkykc.msgparser.MessageParseMgr;
- import com.tmzn.devicelinkykc.util.Encrytion;
- import lombok.extern.slf4j.Slf4j;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import java.math.BigDecimal;
- 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;
- /**
- * @author xp
- * @date 2024/4/13
- * @explain " "
- */
- @Controller
- @Slf4j(topic = "RealTimeStatusPushFrame")
- @RequestMapping
- public class TestController {
- @Autowired
- private DeviceControlerService deviceControlerService;
- @Autowired
- private BillingModelService billingModelService;
- @Autowired
- private BillingModelMapping billingModelMapping;
- @Value("${billingInterface}")
- private String url;
- @Autowired
- private RedisCache redisCache;
- @Autowired
- private MessageParseMgr messageParseMgr;
- @Autowired
- private DeviceMsgHandle deviceMsgHandle;
- @Autowired
- private TransactionFlowPushFrame transactionFlowPushFrame;
- @Autowired
- private OrderStatusService orderStatusService;
- @Autowired
- private TransMoney transMoney;
- @PostMapping("/msg")
- public String testMsg() {
- try {
- // realTimeStatusPushFrame.upStatusDevice(null,);
- String pileCode = "51220002000016";
- QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
- billWapper.eq("pile_code", pileCode);
- BillingModel b = billingModelService.getOne(billWapper);
- //查找所有充电中的订单
- QueryWrapper<OrderStatus> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("id", 57303); //充电中状态上报
- //查询所有充电中设备的最新的订单记录,来上报设备状态消息.........?????????????????
- OrderStatus orderStatus = orderStatusService.getOne(queryWrapper);
- 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(),
- orderStatus.getCreateTime(), orderStatus.getEndTime(), b, orderStatus.getCard(), map,0);
- //deviceMsgHandle.testMsg(message);
- System.out.println( DataConversion.bytesToHexString(params));
- int frameType = DeviceSendYkc.TRANSACTION_RECORDS_REQUEST_16.getFrameType();
- byte[] encrypt = new byte[0];
- encrypt = params;
- byte[] b1 = FrameDataSplicing.spliceing(0,frameType , 0, encrypt, encrypt.length,false);
- System.out.println( DataConversion.bytesToHexString(b1));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "ok";
- }
- @Autowired
- DeviceStatusService deviceStatusService;
- @PostMapping("/parser1")
- public String parser1(@RequestBody String message ) {
- try{
- String str_key = "6492806831843423";
- String code = "";
- byte[] res = Encrytion.rsaEncrypt(str_key.getBytes(),"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKbtY6sYSeN1uv4pafiaTPMHySxmIosW1Jia1mOcaMmWUQrN57uieY++1wkW3LVg4KY7CG/eeQXAwqbbvoax7yMCAwEAAQ==");
- System.out.println(res);
- byte[] res1 = Encrytion.rsaEncrypt(str_key.getBytes(),"MFwwDQYJKoZIhycNAQEBBQADSWAWSAJBAKbtY6sYSeN1uv4pafiaTPMHySxmlosW1Jia1mOcaMmWUQrN57uieY++1wkW3LVg4KY7CG/eeQxAwabbvoax7yMCAWEAAQ==");
- System.out.println(res1);
- QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
- billWapper.eq("pile_code", "32010600530570");
- billWapper.eq("device_imei", "863218078065418");
- BillingModel b = billingModelService.getOne(billWapper);
- if (b == null) {
- log.info("{}上报充电中未匹配计费模型", "32010600530570");
- }
- QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
- deviceStatusQueryWrapper.eq("device_imei", "863343064704539");
- deviceStatusQueryWrapper.last("limit 1");
- DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
- System.out.println(statusServiceOne);
- // deviceMsgHandle.deviceMsg(message);
- }catch (Exception e){
- e.printStackTrace();
- System.out.println(e.getMessage());
- }
- System.out.println(111);
- return "ok";
- }
- @PostMapping("/parser2")
- public String parser2(@RequestBody String message ) {
- //剩余
- byte[] soc = new byte[]{0x00};
- //电池组最高温度
- byte[] battery_temp = {0x32};
- //剩余时间
- byte[] remain_time = {0x00, 0x00};
- //枪线温度
- byte[] guns_line_temp = new byte[1];
- //9.枪线温度
- guns_line_temp[0] = 0x32;
- byte gunsStatus = 3;
- String imei = "868371073352243";
- byte guns = 1;
- double voltage = 136;
- try{
- //重置电压 直流电压放大10倍
- if(gunsStatus== StatusConstant.CHARGING){
- JSONArray dataArray = redisCache.getCacheMapValue("device_last_163",imei+"_"+guns);
- if(dataArray != null){
- //获取soc和剩余时间
- //重置soc
- soc[0] = (byte) (dataArray.getInteger(21+3) & 0xff);
- remain_time[0] = dataArray.getByte(22+3);
- remain_time[1] = dataArray.getByte(23+3);
- // int remainTIme = (dataArray.getInteger(22+3)) | (dataArray.getInteger(23+3)<<8);
- // remain_time[1] = (byte) ((remainTIme >> 8) & 0xFF);
- // remain_time[0] = (byte) (remainTIme & 0xFF);
- //
- // System.out.println(remainTIme);
- // System.out.println(remain_time);
- log.info("充电中-soc:{},remain:{}",soc,remain_time);
- }
- }
- int time = 136;
- byte[] charnging_Time = new byte[2];
- charnging_Time[1] = (byte) ((time >> 8) & 0xFF);
- charnging_Time[0] = (byte) (time & 0xFF);
- System.out.println(charnging_Time);
- }catch (Exception e){
- }
- System.out.println(111);
- return "ok";
- }
- @GetMapping("/test163")
- public AjaxResult test163(HttpServletRequest request ) {
- String data = request.getParameter("data");
- List<Integer> split = Arrays.stream(data.split(","))
- .map(Integer::parseInt) // 将 String 转换为 Integer
- .collect(Collectors.toList()); // 收集结果到 List 中
- List<List<Integer>> packages = Encrytion.parseMorePackage(split);
- System.out.println(111);
- // JSONArray objects = new JSONArray(split);
- // JSONObject obj = new JSONObject();
- // obj.put("data",objects);
- // JSONObject object = messageParseMgr.parseMessage("75960_103", obj);
- // System.out.println(object);
- return null;
- }
- @GetMapping("/parser")
- public AjaxResult parser(HttpServletRequest request ) {
- String data = request.getParameter("data");
- List<Integer> split = Arrays.stream(data.split(","))
- .map(Integer::parseInt) // 将 String 转换为 Integer
- .collect(Collectors.toList()); // 收集结果到 List 中
- List<List<Integer>> packages = Encrytion.parseMorePackage(split);
- System.out.println(packages);
- for(int i=0;i<packages.size();i++){
- JSONObject obj = new JSONObject();
- obj.put("data",packages.get(i));
- System.out.println("parser:"+"75960_"+packages.get(i).get(1));
- JSONObject object = messageParseMgr.parseMessage("75960_"+packages.get(i).get(1),obj);
- System.out.println(object);
- if(object!=null){
- String m = object.toString();
- System.out.println(m);
- }
- }
- System.out.println(111);
- // JSONArray objects = new JSONArray(split);
- // JSONObject obj = new JSONObject();
- // obj.put("data",objects);
- // JSONObject object = messageParseMgr.parseMessage("75960_103", obj);
- // System.out.println(object);
- return null;
- }
- @GetMapping("/test")
- public String test(@RequestParam("method") String method, @RequestParam("imei") String imei) {
- String deviceId = imei;
- String ccid = imei;
- if ("start".equals(method)) {
- deviceControlerService.startCharge(imei, imei, 1,50000);
- } else if ("stop".equals(method)) {
- deviceControlerService.stopCharge(imei, imei, 1);
- } else if ("port".equals(method)) {
- DeviceParam deviceParam = new DeviceParam();
- deviceParam.setDeviceId(imei);
- deviceParam.setCcid(imei);
- deviceControlerService.sendPortDetailCmd(deviceParam);
- } else if ("restartDevice".equals(method)) {
- deviceControlerService.restart(imei, imei);
- } else if ("rest".equals(method)) {
- deviceControlerService.reset(imei, imei);
- }
- return "ok";
- }
- private static final Logger logger = LoggerFactory.getLogger(DeviceMsgHandle.class);
- @GetMapping("/test2")
- public String test2(@RequestParam("pileCode") String pileCode) {
- //调用重启
- // redisCache.setCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, pileCode+"_"+1,System.currentTimeMillis());
- // return "ok";
- // //标记最后订单时间 5分钟内不上报空闲状态 避免刚下单状态还没更新就被freeTask任务给顶掉了
- new Thread(() -> {
- try {
- Thread.sleep(5000); // 延迟 5 秒
- DeviceParam dataParam = new DeviceParam();
- dataParam.setDeviceId("123456");
- dataParam.setCcid("123456");
- // deviceControlerService.sendPortDetailCmd(dataParam);
- logger.info(":主动下发103消息");
- } catch (Exception e) {
- logger.info(":主动下发103消息异常" + e.getMessage());
- }
- }).start();
- // try{
- // long ts = redisCache.getCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, pileCode+"_1");
- // if(ts!=0){
- // long ts1 = System.currentTimeMillis();
- // if((ts1-ts)<300*1000){
- // return "ok";
- // }
- // }
- // }catch (Exception e){
- // return "error";
- // }
- return "ok";
- }
- @Autowired LoginFrame loginFrame;
- @GetMapping("/test3")
- public String test3(@RequestParam("pileCode") String pileCode) throws Exception {
- //调用重启
- loginFrame.test(pileCode);
- return "ok";
- }
- @GetMapping("/test1")
- public String test1(@RequestParam("pileCode") String pileCode) {
- //调用重启
- try{
- String url = "http://127.0.0.1:8063/api/device/restLogin/"+pileCode;
- HttpResponse execute = HttpRequest.post(url)
- .timeout(3000)
- .execute();
- String body = execute.body();
- System.out.println("reset login body:>>>"+body);
- } catch (Exception ex) {
- System.out.println("reset error :>>>"+ex.toString());
- }
- return "ok";
- }
- @RequestMapping("/testElec")
- public JSONObject testCompute(@RequestParam("end")Long end,@RequestParam("start")Long star,@RequestParam("imei")String imei,@RequestParam("port")int port) {
- QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
- BillingModel one = billingModelService.getOne(billingModelQueryWrapper);
- BillingModelDTO billingModelDTO = billingModelMapping.billingModelToBillingModelDto(one);
- HashMap<String, Object> map = new HashMap<>();
- map.put("port",port);
- map.put("billingModel",billingModelDTO);
- map.put("startTime",star/1000);
- map.put("endTime",end/1000);
- JSONObject jsonObject = new JSONObject(map);
- String s = jsonObject.toString();
- HttpResponse execute = HttpRequest.post(url)
- .form("data",s)
- .timeout(3000)
- .execute();
- int status = execute.getStatus();
- String body = execute.body();
- System.out.println("body:>>>"+body);
- return null;
- }
- }
|