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.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 billWapper = new QueryWrapper<>(); billWapper.eq("pile_code", pileCode); BillingModel b = billingModelService.getOne(billWapper); //查找所有充电中的订单 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("id", 57303); //充电中状态上报 //查询所有充电中设备的最新的订单记录,来上报设备状态消息.........????????????????? OrderStatus orderStatus = orderStatusService.getOne(queryWrapper); Map map = transMoney.compute(orderStatus.getGunsCode(), b, orderStatus.getCreateTime(), orderStatus.getEndTime()); 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 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 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 split = Arrays.stream(data.split(",")) .map(Integer::parseInt) // 将 String 转换为 Integer .collect(Collectors.toList()); // 收集结果到 List 中 List> 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 split = Arrays.stream(data.split(",")) .map(Integer::parseInt) // 将 String 转换为 Integer .collect(Collectors.toList()); // 收集结果到 List 中 List> packages = Encrytion.parseMorePackage(split); System.out.println(packages); for(int i=0;i { 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 billingModelQueryWrapper = new QueryWrapper<>(); BillingModel one = billingModelService.getOne(billingModelQueryWrapper); BillingModelDTO billingModelDTO = billingModelMapping.billingModelToBillingModelDto(one); HashMap 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; } }