| | |
| | | public R<BigDecimal> getSumDegreeBySiteIds(@RequestParam("siteIds") List<Integer> SiteIds){ |
| | | return R.fail("获取站点集合中总的充电量失败:" + throwable.getMessage()); |
| | | } |
| | | |
| | | // @Override |
| | | // public R<List<TChargingOrder>> getOrderListByStatus(List<Integer> statusList) { |
| | | // return R.fail("获取站点集合中总的充电量失败:" + throwable.getMessage()); |
| | | // } |
| | | |
| | | @Override |
| | | public R<Long> addChargingOrder(TChargingOrder chargingOrder) { |
| | | return R.fail("添加订单失败:" + throwable.getMessage()); |
| | | } |
| | | }; |
| | | } |
| | | } |
| | |
| | | */ |
| | | @GetMapping("/t-charging-order/getSumDegreeBySiteIds") |
| | | R<BigDecimal> getSumDegreeBySiteIds(@RequestParam("siteIds") List<Integer> SiteIds); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // /** |
| | | // * 获取充电订单列表 |
| | | // * @param statusList |
| | | // * @return |
| | | // */ |
| | | // @GetMapping("/t-charging-order/getOrderListByStatus") |
| | | // R<List<TChargingOrder>> getOrderListByStatus(List<Integer> statusList); |
| | | |
| | | /** |
| | | * 添加订单 |
| | | * @param chargingOrder |
| | | * @return |
| | | */ |
| | | @PostMapping("/t-charging-order/addChargingOrder") |
| | | R<Long> addChargingOrder(@RequestBody TChargingOrder chargingOrder); |
| | | } |
| | |
| | | return df.format(time); |
| | | } |
| | | |
| | | // string转LocalDateTime |
| | | public static LocalDateTime stringToLocalDateTime(String time) { |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | return LocalDateTime.parse(time, formatter); |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.constant; |
| | | |
| | | public class ChargePileInterface { |
| | | public static final String TOKEN_KEY = "charge_token:"; |
| | | public static final String OperatorID = "734810353"; |
| | | // 获取token |
| | | public static final String QUERY_TOKEN = "http://tld.itsou.top/evcs/tld/query_token"; |
| | | // 查询充电站信息 |
| | | public static final String QUERY_STATIONS_INFO = "http://tld.itsou.top/evcs/tld/query_stations_info"; |
| | | // 设备接口状态查询 |
| | | public static final String QUERY_STATION_STATUS = "http://tld.itsou.top/evcs/tld/query_station_status"; |
| | | // 查询业务策略信息 |
| | | public static final String QUERY_EQUIP_BUSINESS_POLICY = "http://tld.itsou.top/evcs/tld/query_equip_business_policy"; |
| | | // 请求设备认证 |
| | | public static final String QUERY_EQUIP_AUTH = "http://tld.itsou.top/evcs/tld/query_equip_auth"; |
| | | // 请求启动充电 |
| | | public static final String QUERY_START_CHARGE = "http://tld.itsou.top/evcs/tld/query_start_charge"; |
| | | // 查询充电状态 |
| | | public static final String QUERY_EQUIP_CHARGE_STATUS = "http://tld.itsou.top/evcs/tld/query_equip_charge_status"; |
| | | // 请求停止充电 |
| | | public static final String QUERY_STOP_CHARGE = "http://tld.itsou.top/evcs/tld/query_stop_charge"; |
| | | // 自助备案车牌号 |
| | | public static final String QUERY_MERCHANT_VEHICLES = "http://tld.itsou.top/evcs/tld/query_merchant_vehicles"; |
| | | // 获取商户企业账户余额 |
| | | public static final String QUERY_CASHBALANCE = "http://tld.itsou.top/evcs/tld/query_cashbalance"; |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.ConnectorInfo; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.EquipmentInfos; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.PageInfo; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.StationInfos; |
| | | import com.ruoyi.chargingPile.tulaidian.util.ChargePileHttpUtil; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 接口控制器提供 |
| | | * |
| | | * @author stylefeng |
| | | * @Date 2018/7/20 23:39 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/chargingPileInfo") |
| | | public class ChargingPileInfoController { |
| | | @Autowired |
| | | private ChargePileHttpUtil chargePileHttpUtil; |
| | | private static final double EARTH_RADIUS = 6371.0; // 地球半径,单位为千米 |
| | | |
| | | /** |
| | | * 计算两点之间的距离,单位为千米 |
| | | * |
| | | * @param lat1 第一个点的纬度 |
| | | * @param lon1 第一个点的经度 |
| | | * @param lat2 第二个点的纬度 |
| | | * @param lon2 第二个点的经度 |
| | | * @return 两点之间的距离,单位为千米 |
| | | */ |
| | | public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) { |
| | | double dLat = Math.toRadians(lat2 - lat1); |
| | | double dLon = Math.toRadians(lon2 - lon1); |
| | | |
| | | lat1 = Math.toRadians(lat1); |
| | | lat2 = Math.toRadians(lat2); |
| | | |
| | | double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + |
| | | Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); |
| | | double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); |
| | | |
| | | return EARTH_RADIUS * c; |
| | | } |
| | | /** |
| | | * 司机端-获取充电桩列表 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/chargingPileList") |
| | | @ApiOperation(value = "司机端-获取充电桩列表", tags = {"司机端-获取充电桩列表"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "电站类型 0=不限 1=公共 50=个人 100=公交 101=环卫(专用) 102=物流(专用) 103=出租车(专用) 255=其他", name = "type", required = false, dataType = "string"), |
| | | @ApiImplicitParam(value = "电站距离 不限=0 1km内=1 2km内=2 3km内=3 5km内=4 10km内=5 50km内=6 100km内=7 ", name = "distance", required = false, dataType = "int"), |
| | | @ApiImplicitParam(value = "设备状态 不限=0 1=只看空闲", name = "status", required = false, dataType = "int"), |
| | | @ApiImplicitParam(value = "电站名称/目标地址", name = "name", required = false, dataType = "string"), |
| | | @ApiImplicitParam(value = "pageNo", name = "pageNo", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "pageSize", name = "pageSize", required = true, dataType = "string"), |
| | | @ApiImplicitParam(value = "lon", name = "经度", required = false, dataType = "string"), |
| | | @ApiImplicitParam(value = "lat", name = "纬度", required = false, dataType = "string"), |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), |
| | | }) |
| | | public R<String> chargingPileList(String type, Integer distance, |
| | | Integer status, |
| | | String name, |
| | | String lon, |
| | | String lat, |
| | | Integer pageNo, Integer pageSize){ |
| | | PageInfo pageInfo = new PageInfo(); |
| | | List<StationInfos> result = getStationInfos(); |
| | | // 电站类型 |
| | | if (StringUtils.hasLength(type) && (!type.equals("0"))){ |
| | | List<Integer> list = Arrays.stream(type.split(",")).map(Integer::parseInt).collect(Collectors.toList()); |
| | | result = result.stream().filter(item -> list.contains(item.getStationType())).collect(Collectors.toList()); |
| | | } |
| | | // 电站名称/目标地址 |
| | | if(StringUtils.hasLength(name)){ |
| | | result = result.stream().filter(item -> item.getStationName().contains(name) || |
| | | item.getAddress().contains(name)).collect(Collectors.toList()); |
| | | } |
| | | |
| | | for (StationInfos stationInfo : result) { |
| | | if (StringUtils.hasLength(lon)){ |
| | | double v = calculateDistance( |
| | | stationInfo.getStationLat(), |
| | | stationInfo.getStationLng(), |
| | | Double.parseDouble(lat), |
| | | Double.parseDouble(lon) |
| | | ); |
| | | stationInfo.setDistance(String.valueOf(Math.abs(v))); |
| | | }else { |
| | | stationInfo.setDistance("0"); |
| | | } |
| | | |
| | | List<EquipmentInfos> equipmentInfos = stationInfo.getEquipmentInfos(); |
| | | int a = 0; |
| | | int b = 0; |
| | | for (EquipmentInfos equipmentInfo : equipmentInfos) { |
| | | if (equipmentInfo.getEquipmentType()==1){ |
| | | a++; |
| | | } |
| | | if (equipmentInfo.getEquipmentType()==2){ |
| | | b++; |
| | | } |
| | | } |
| | | stationInfo.setFastTotal(a); |
| | | stationInfo.setSnowTotal(b); |
| | | stationInfo.setFast(a); |
| | | stationInfo.setSnow(b); |
| | | } |
| | | if(Objects.nonNull(distance) && distance != 0){ |
| | | switch (distance){ |
| | | case 1: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 1).collect(Collectors.toList()); |
| | | break; |
| | | case 2: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 2).collect(Collectors.toList()); |
| | | break; |
| | | case 3: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 3).collect(Collectors.toList()); |
| | | break; |
| | | case 4: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 5).collect(Collectors.toList()); |
| | | break; |
| | | case 5: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 10).collect(Collectors.toList()); |
| | | break; |
| | | case 6: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 50).collect(Collectors.toList()); |
| | | break; |
| | | case 7: |
| | | result = result.stream().filter(item -> Double.parseDouble(item.getDistance()) <= 100).collect(Collectors.toList()); |
| | | break; |
| | | } |
| | | } |
| | | List<String> stationIDs = result.stream() |
| | | .map(StationInfos::getStationID) |
| | | .collect(Collectors.toList()); |
| | | String obj = chargePileHttpUtil.queryStationStatus(stationIDs); |
| | | JSONObject jsonObject1 = JSONObject.parseObject(obj); |
| | | JSONArray stationStatusInfos = jsonObject1.getJSONArray("StationStatusInfos"); |
| | | for (StationInfos stationInfo : result) { |
| | | for (EquipmentInfos equipmentInfo : stationInfo.getEquipmentInfos()) { |
| | | for (ConnectorInfo connectorInfo : equipmentInfo.getConnectorInfos()) { |
| | | for (Object stationStatusInfo : stationStatusInfos) { |
| | | JSONObject jsonObject2 = (JSONObject) stationStatusInfo; |
| | | String stationID = jsonObject2.getString("StationID"); |
| | | JSONArray connectorStatusInfos = jsonObject2.getJSONArray("ConnectorStatusInfos"); |
| | | if (connectorStatusInfos != null) { |
| | | for (Object connectorStatusInfo : connectorStatusInfos) { |
| | | JSONObject jsonObject3 = (JSONObject) connectorStatusInfo; |
| | | String status1 = jsonObject3.getString("ConnectorID"); |
| | | if (connectorInfo.getConnectorID().equals(status1)){ |
| | | Integer status2 = jsonObject3.getInteger("Status"); |
| | | if (status2==1){ |
| | | connectorInfo.setStatus(1); |
| | | }else { |
| | | connectorInfo.setStatus(2); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 电站状态 |
| | | if (Objects.nonNull(status) && status == 1) { |
| | | Iterator<StationInfos> iterator1 = result.iterator(); |
| | | while (iterator1.hasNext()) { |
| | | StationInfos next = iterator1.next(); |
| | | for (Object stationStatusInfo : stationStatusInfos) { |
| | | JSONObject jsonObject2 = (JSONObject) stationStatusInfo; |
| | | String stationID = jsonObject2.getString("StationID"); |
| | | if (stationID != null && stationID.equals(next.getStationID())) { |
| | | JSONArray connectorStatusInfos = jsonObject2.getJSONArray("ConnectorStatusInfos"); |
| | | if (connectorStatusInfos != null) { |
| | | for (Object connectorStatusInfo : connectorStatusInfos) { |
| | | JSONObject jsonObject3 = (JSONObject) connectorStatusInfo; |
| | | Integer status1 = jsonObject3.getInteger("Status"); |
| | | if (status1 != null && status1 == 1) { |
| | | break; |
| | | }else { |
| | | iterator1.remove(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | result.sort(Comparator.comparing(StationInfos::getDistance)); |
| | | pageInfo.setTotal(result.size()); |
| | | |
| | | List<StationInfos> testing = testing(result.size(), pageNo, pageSize, result); |
| | | |
| | | // TODO 数据存储 |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | public static List<StationInfos> testing(long total, long current, long size, List<StationInfos> str){ |
| | | List<StationInfos> result = new ArrayList<>(); |
| | | //获取初始化分页结构 |
| | | Page<StationInfos> page = new Page(total, size, current - 1); |
| | | //获取集合下标初始值 |
| | | long startIndex = page.getCurrent(); |
| | | //获取集合下标结束值 |
| | | long endInddex = 0; |
| | | if(startIndex + page.getCurrent() >= total || size > total){ |
| | | endInddex = total; |
| | | }else { |
| | | endInddex = Math.min(startIndex + page.getSize(), total); |
| | | } |
| | | //如果输入的开始查询下标大于集合大小,则查询为空值 |
| | | if(startIndex > total){ |
| | | result = Collections.emptyList(); |
| | | }else{ |
| | | result = str.subList((int)startIndex,(int)endInddex); |
| | | } |
| | | return result; |
| | | } |
| | | private List<StationInfos> getStationInfos(){ |
| | | String s = chargePileHttpUtil.queryStationsInfo(1, 199); |
| | | // 将s字符串转化为json 然后转化为实体类PageInfo |
| | | JSONObject jsonObject = JSONObject.parseObject(s); |
| | | PageInfo pageInfo = JSON.parseObject(jsonObject.toJSONString(), PageInfo.class); |
| | | List<StationInfos> result = new ArrayList<>(); |
| | | int itemSize = pageInfo.getItemSize(); |
| | | if(itemSize>199){ |
| | | result.addAll(pageInfo.getStationInfos()); |
| | | int i = itemSize / 199; |
| | | for (int j = 2; j < i + 2; j++) { |
| | | s = chargePileHttpUtil.queryStationsInfo(j, 199); |
| | | // 将s字符串转化为json 然后转化为实体类PageInfo |
| | | jsonObject = JSONObject.parseObject(s); |
| | | pageInfo = JSON.parseObject(jsonObject.toJSONString(), PageInfo.class); |
| | | result.addAll(pageInfo.getStationInfos()); |
| | | } |
| | | }else { |
| | | result.addAll(pageInfo.getStationInfos()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | } |
| | | |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.ChargeRecord; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.ChargeStatus; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.TContent; |
| | | import com.ruoyi.chargingPile.tulaidian.service.IContentService; |
| | | import com.ruoyi.chargingPile.tulaidian.util.AesEncryption; |
| | | import com.ruoyi.chargingPile.tulaidian.util.HMacMD5Util; |
| | | import com.ruoyi.chargingPile.tulaidian.util.SequenceGenerator; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderClient; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 广告控制器 |
| | | */ |
| | | @Api |
| | | @RestController |
| | | @RequestMapping("/orderCallBack") |
| | | public class NotifyController { |
| | | @Autowired |
| | | private ChargingOrderClient chargingOrderClient; |
| | | @Autowired |
| | | private IContentService contentService; |
| | | private static final String OperatorID = "MA01H3BQ3"; |
| | | private static final String OperatorSecret = "f1331ef0b37c2d2"; |
| | | private static final String SigSecret = "a6fedf0e1b27d6f8"; |
| | | private static final String DataSecret = "50a61b93919c9606"; |
| | | private static final String DataSecretIV = "7c8ac6861661d586"; |
| | | |
| | | private static final String OperatorSecretOther = "f1331ef0b37c2d2"; |
| | | private static final String SigSecretOther = "a6fedf0e1b27d6f8"; |
| | | private static final String DataSecretOther = "50a61b93919c9606"; |
| | | private static final String DataSecretIVOther = "7c8ac6861661d586"; |
| | | |
| | | // 结束充电后 特来电主动 推送充电订单信息 |
| | | @ResponseBody |
| | | @PostMapping("/notification_charge_order_info") |
| | | public R notification_charge_order_info(@RequestBody String json) throws ParseException { |
| | | TContent tContent = new TContent(); |
| | | tContent.setType(5); |
| | | tContent.setContent(json); |
| | | tContent.setCreateTime(new Date()); |
| | | contentService.save(tContent); |
| | | JSONObject jsonObject1 = JSONObject.parseObject(json); |
| | | String data = jsonObject1.getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, data); |
| | | System.err.println(decrypt); |
| | | JSONObject jsonObject = JSONObject.parseObject(decrypt); |
| | | System.err.println("结束充电后 特来电主动推送订单信息"); |
| | | ChargeRecord chargeRecord = JSON.parseObject(jsonObject.toJSONString(), ChargeRecord.class); |
| | | // 新增订单 |
| | | TChargingOrder chargingOrder = new TChargingOrder(); |
| | | chargingOrder.setCode(chargeRecord.getStartChargeSeq()); |
| | | chargingOrder.setOrderSource(2); |
| | | // TODO 运营商id |
| | | chargingOrder.setTripartitePlatformName("途来电"); |
| | | chargingOrder.setStartChargeSeq(chargeRecord.getStartChargeSeq()); |
| | | chargingOrder.setSourceName("途来电"); |
| | | chargingOrder.setStartTime(DateUtils.stringToLocalDateTime(chargeRecord.getStartTime())); |
| | | chargingOrder.setEndTime(DateUtils.stringToLocalDateTime(chargeRecord.getEndTime())); |
| | | chargingOrder.setStatus(5); |
| | | chargingOrder.setEndMode(1); |
| | | chargingOrder.setElectrovalence(chargeRecord.getTotalElecMoney()); |
| | | chargingOrder.setServiceCharge(chargeRecord.getTotalSeviceMoney()); |
| | | chargingOrder.setTotalElectricity(chargeRecord.getTotalPower()); |
| | | chargingOrder.setPaymentAmount(chargeRecord.getTotalMoney()); |
| | | R<Long> orderIdR = chargingOrderClient.addChargingOrder(chargingOrder); |
| | | if(orderIdR.getCode() == 200){ |
| | | // TODO 充电明细 |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/notification_equip_charge_status") |
| | | public R notification_equip_charge_status(@RequestBody String json) throws ParseException { |
| | | TContent tContent = new TContent(); |
| | | tContent.setType(1); |
| | | tContent.setContent(json); |
| | | tContent.setCreateTime(new Date()); |
| | | contentService.save(tContent); |
| | | JSONObject jsonObject1 = JSONObject.parseObject(json); |
| | | String data = jsonObject1.getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, data); |
| | | System.err.println(decrypt); |
| | | JSONObject jsonObject = JSONObject.parseObject(decrypt); |
| | | System.err.println("特来电主动推送订单状态"); |
| | | ChargeStatus chargeStatus = JSON.parseObject(jsonObject.toJSONString(), ChargeStatus.class); |
| | | R<TChargingOrder> chargeOrderR = chargingOrderClient.getChargingOrderByStartChargeSeq(chargeStatus.getStartChargeSeq()); |
| | | TChargingOrder chargingOrder = chargeOrderR.getData(); |
| | | if (chargingOrder!=null){ |
| | | // 修改订单状态 |
| | | chargingOrder.setStatus(chargeStatus.getStartChargeSeqStat()); |
| | | chargingOrderClient.updateChargingOrder(chargingOrder); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.dao; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.TContent; |
| | | |
| | | public interface ContentMapper extends BaseMapper<TContent> { |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | @Data |
| | | @ApiModel(description = "充电详情实体类") |
| | | public class ChargeDetail { |
| | | @ApiModelProperty(value = "开始时间", example = "2017-08-08 11:29:29") |
| | | private String DetailStartTime; |
| | | @ApiModelProperty(value = "结束时间") |
| | | private String DetailEndTime; |
| | | @ApiModelProperty(value = "时段电价") |
| | | private BigDecimal ElecPrice; |
| | | @ApiModelProperty(value = "时段服务费价格") |
| | | private BigDecimal SevicePrice; |
| | | @ApiModelProperty(value = "时段充电量") |
| | | private BigDecimal DetailPower; |
| | | @ApiModelProperty(value = "时段电费") |
| | | private BigDecimal DetailElecMoney; |
| | | @ApiModelProperty(value = "时段服务费") |
| | | private BigDecimal DetailSeviceMoney; |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | @ApiModel(description = "充电记录实体类") |
| | | @Data |
| | | public class ChargeRecord { |
| | | |
| | | @ApiModelProperty(value = "充电订单号\n" + |
| | | "\n", example = "395815801201708081212000874") |
| | | private String startChargeSeq; |
| | | |
| | | @ApiModelProperty(value = "连接器ID", example = "3702120244206") |
| | | private String connectorID; |
| | | |
| | | @ApiModelProperty(value = "开始时间", example = "2017-08-08 11:29:29") |
| | | private String startTime; |
| | | |
| | | @ApiModelProperty(value = "结束时间", example = "2017-08-08 11:30:30") |
| | | private String endTime; |
| | | |
| | | @ApiModelProperty(value = "总电量", example = "0.00") |
| | | private BigDecimal totalPower; |
| | | |
| | | @ApiModelProperty(value = "电费总额", example = "0.00") |
| | | private BigDecimal totalElecMoney; |
| | | |
| | | @ApiModelProperty(value = "服务费总额", example = "0.00") |
| | | private BigDecimal totalSeviceMoney; |
| | | |
| | | @ApiModelProperty(value = "总金额", example = "0.00") |
| | | private BigDecimal totalMoney; |
| | | |
| | | @ApiModelProperty(value = "停止原因", example = "2") |
| | | private Integer stopReason; |
| | | |
| | | @ApiModelProperty(value = "总时长", example = "0") |
| | | private Integer sumPeriod; |
| | | |
| | | @ApiModelProperty(value = "充电详情列表") |
| | | private List<ChargeDetail> chargeDetails; |
| | | } |
| | | |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | @ApiModel(description = "请求停止充电返回对象") |
| | | public class ChargeStartResponse { |
| | | |
| | | @ApiModelProperty(value = "充电订单状态 1:启动中\n" + |
| | | "\n" + |
| | | "2:充电中\n" + |
| | | "\n" + |
| | | "3:停止中\n" + |
| | | "\n" + |
| | | "4:已结束\n" + |
| | | "\n" + |
| | | "5:未知") |
| | | private int startChargeSeqStat; |
| | | |
| | | @ApiModelProperty(value = "充电订单号") |
| | | private String startChargeSeq; |
| | | |
| | | @ApiModelProperty(value = "连接器ID", example = "3702120244401") |
| | | private String connectorID; |
| | | |
| | | @ApiModelProperty(value = "操作结果0:成功 1:失败") |
| | | private int succStat; |
| | | |
| | | @ApiModelProperty(value = "失败原因 0:无;\n" + |
| | | "\n" + |
| | | "1:此设备不存在;\n" + |
| | | "\n" + |
| | | "2:此设备离线:\n" + |
| | | "\n" + |
| | | "3:设备已停止充电;\n" + |
| | | "\n" + |
| | | "4~99:自定义") |
| | | private int failReason; |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @ApiModel(value = "充电订单对象") |
| | | @Data |
| | | public class ChargeStatus { |
| | | @ApiModelProperty(value = "累计充电时间") |
| | | private Long chargingTime; |
| | | @ApiModelProperty(value = "充电站名称") |
| | | private String stationName; |
| | | @ApiModelProperty(value = "桩名称") |
| | | private String pileName; |
| | | @ApiModelProperty(value = "桩编号") |
| | | private String equipmentID; |
| | | @ApiModelProperty(value = "枪名称") |
| | | private String gunName; |
| | | @ApiModelProperty(value = "枪编号") |
| | | private String connectorID; |
| | | @ApiModelProperty(value = "电费总额") |
| | | private Double elecMoney; |
| | | @ApiModelProperty(value = "充电总度数") |
| | | private Double totalPower; |
| | | @ApiModelProperty(value = "充电订单状态 1:启动中; 2:充电中; 3:停止中;4:已结束 5:未知 6:启动失败") |
| | | private Integer startChargeSeqStat; |
| | | @ApiModelProperty(value = "电池剩余电量") |
| | | private Integer soc; |
| | | @ApiModelProperty(value = "启动充电失败原因") |
| | | private String identCode; |
| | | @ApiModelProperty(value = "订单id") |
| | | private Long id; |
| | | @ApiModelProperty(value = "充电订单号") |
| | | private String startChargeSeq; |
| | | @ApiModelProperty(value = "充电设备接口 状态 1:空闲; 2:占用(未充电) 3:占用(充电中) 4:占用(预约锁定); 255:故障") |
| | | private Integer connectorStatus; |
| | | @ApiModelProperty(value = "电流A相") |
| | | private Double currentA; |
| | | @ApiModelProperty(value = "电流B相") |
| | | private Double currentB; |
| | | @ApiModelProperty(value = "电流C相") |
| | | private Double currentC; |
| | | @ApiModelProperty(value = "电压A相") |
| | | private Double voltageA; |
| | | @ApiModelProperty(value = "电压B相") |
| | | private Double voltageB; |
| | | @ApiModelProperty(value = "电压C相") |
| | | private Double voltageC; |
| | | @ApiModelProperty(value = "充电开始时间") |
| | | private String startTime; |
| | | @ApiModelProperty(value = "充电采样时间") |
| | | private String endTime; |
| | | @ApiModelProperty(value = "服务费总额") |
| | | private Double seviceMoney; |
| | | @ApiModelProperty(value = "总金额") |
| | | private Double totalMoney; |
| | | @ApiModelProperty(value = "时段数N") |
| | | private Integer sumPeriod; |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class ConnectorInfo { |
| | | @ApiModelProperty(value = "连接器ID") |
| | | private String connectorID; |
| | | |
| | | @ApiModelProperty(value = "连接器名称") |
| | | private String connectorName; |
| | | |
| | | @ApiModelProperty(value = "连接器类型 1:家用插座(模式2);\n" + |
| | | "2:交流接口插座(模式3,连 接方式B);\n" + |
| | | "3:交流接口插头(带枪线, 模式3,连接方式C);\n" + |
| | | "4:直流接口枪头(带枪线, 模式4);\n" + |
| | | "5:无线充电座; 6:其他") |
| | | private int connectorType; |
| | | |
| | | @ApiModelProperty(value = "电压上限") |
| | | private int voltageUpperLimits; |
| | | |
| | | @ApiModelProperty(value = "电压下限") |
| | | private int voltageLowerLimits; |
| | | |
| | | @ApiModelProperty(value = "电流") |
| | | private int current; |
| | | |
| | | @ApiModelProperty(value = "功率") |
| | | private double power; |
| | | |
| | | @ApiModelProperty(value = "停车位编号") |
| | | private String parkNo; |
| | | @ApiModelProperty(value = "状态 1空闲 2占用") |
| | | private Integer status; |
| | | |
| | | @ApiModelProperty(value = "国家标准") |
| | | private int nationalStandard; |
| | | @ApiModelProperty(value = "枪类型 1=快充 2=慢充") |
| | | private Integer gunType; |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | @ApiModel(value = "充电站对象") |
| | | |
| | | public class EquipmentInfos { |
| | | @ApiModelProperty(value = "设备ID") |
| | | private String equipmentID; |
| | | |
| | | @ApiModelProperty(value = "设备名称") |
| | | private String equipmentName; |
| | | |
| | | @ApiModelProperty(value = "制造商ID") |
| | | private String manufacturerID; |
| | | |
| | | @ApiModelProperty(value = "制造商名称") |
| | | private String manufacturerName; |
| | | |
| | | @ApiModelProperty(value = "设备型号") |
| | | private String equipmentModel; |
| | | |
| | | @ApiModelProperty(value = "生产日期") |
| | | private String productionDate; |
| | | |
| | | @ApiModelProperty(value = "设备类型 1:直流设备; 2:交流设备;\n" + |
| | | "3:交直流一体设备; 4:无线设备;\n" + |
| | | "5:其他") |
| | | private int equipmentType; |
| | | |
| | | @ApiModelProperty(value = "设备经度") |
| | | private double equipmentLng; |
| | | |
| | | @ApiModelProperty(value = "设备纬度") |
| | | private double equipmentLat; |
| | | |
| | | @ApiModelProperty(value = "功率") |
| | | private double power; |
| | | @ApiModelProperty(value = "枪类型 1=快充 2=慢充") |
| | | private Integer gunType; |
| | | @ApiModelProperty(value = "连接器信息列表") |
| | | private List<ConnectorInfo> connectorInfos; |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | |
| | | @ApiModel(description = "推送统一接收实体类") |
| | | public class OperatorData { |
| | | |
| | | @ApiModelProperty(value = "运营商ID", example = "395815801") |
| | | private String OperatorID; |
| | | |
| | | @ApiModelProperty(value = "数据内容", example = "MdtylP2lneRGc9XzcskU+I+sLFM0lW0OmxV4yRCW7Yoqy7XWGbN4g0sNMxyALuT59PsBJ1Oy4uNbCcvjTD2eJFnSSx0UDBOMu4KFkIjYrJp2IWroDD/960epFXvTEldX+c92DmO2HI9yUiVDYMHdt3P4in69l4RVRUy9Czos7H4T5GApCizy42jXEGv1UgON") |
| | | private String Data; |
| | | |
| | | @ApiModelProperty(value = "时间戳", example = "20180517090848") |
| | | private String TimeStamp; |
| | | |
| | | @ApiModelProperty(value = "序列号", example = "0001") |
| | | private String Seq; |
| | | |
| | | @ApiModelProperty(value = "签名", example = "AD80102D05D1C31C2056DE130333A8CE") |
| | | private String Sig; |
| | | |
| | | // Getters and Setters |
| | | public String getOperatorID() { |
| | | return OperatorID; |
| | | } |
| | | |
| | | public void setOperatorID(String operatorID) { |
| | | OperatorID = operatorID; |
| | | } |
| | | |
| | | public String getData() { |
| | | return Data; |
| | | } |
| | | |
| | | public void setData(String data) { |
| | | Data = data; |
| | | } |
| | | |
| | | public String getTimeStamp() { |
| | | return TimeStamp; |
| | | } |
| | | |
| | | public void setTimeStamp(String timeStamp) { |
| | | TimeStamp = timeStamp; |
| | | } |
| | | |
| | | public String getSeq() { |
| | | return Seq; |
| | | } |
| | | |
| | | public void setSeq(String seq) { |
| | | Seq = seq; |
| | | } |
| | | |
| | | public String getSig() { |
| | | return Sig; |
| | | } |
| | | |
| | | public void setSig(String sig) { |
| | | Sig = sig; |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | @ApiModel(value = "分页对象") |
| | | public class PageInfo { |
| | | private int pageNo; |
| | | private int pageCount; |
| | | private int itemSize; |
| | | private int total; |
| | | private List<StationInfos> stationInfos; |
| | | |
| | | public PageInfo(int pageNo, int pageCount) { |
| | | this.pageNo = pageNo; |
| | | this.pageCount = pageCount; |
| | | } |
| | | public PageInfo() { |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import com.ruoyi.integration.api.elutong.model.EquipmentInfo; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @ApiModel(value = "充电站对象") |
| | | @Data |
| | | public class StationInfos { |
| | | @ApiModelProperty(value = "距离我xxKM") |
| | | private String distance; |
| | | @ApiModelProperty(value = "站点ID") |
| | | private String stationID; |
| | | |
| | | @ApiModelProperty(value = "运营商ID") |
| | | private String operatorID; |
| | | |
| | | @ApiModelProperty(value = "设备所有者ID") |
| | | private String equipmentOwnerID; |
| | | |
| | | @ApiModelProperty(value = "站点名称") |
| | | private String stationName; |
| | | |
| | | @ApiModelProperty(value = "国家代码") |
| | | private String countryCode; |
| | | |
| | | @ApiModelProperty(value = "区域代码") |
| | | private String areaCode; |
| | | |
| | | @ApiModelProperty(value = "地址") |
| | | private String address; |
| | | |
| | | @ApiModelProperty(value = "站点电话") |
| | | private String stationTel; |
| | | |
| | | @ApiModelProperty(value = "服务电话") |
| | | private String serviceTel; |
| | | |
| | | @ApiModelProperty(value = "站点类型 1:公共; 50:个人;\n" + |
| | | "100:公交(专用);\n" + |
| | | "101:环卫(专用);\n" + |
| | | "102:物流(专用);\n" + |
| | | "103:出租车(专用); 255:其他") |
| | | private int stationType; |
| | | |
| | | @ApiModelProperty(value = "站点状态 0:未知;\n" + |
| | | "1:建设中;\n" + |
| | | "5:关闭下线; 6:维护中;\n" + |
| | | "50:正常使用") |
| | | private int stationStatus; |
| | | |
| | | @ApiModelProperty(value = "停车位数量") |
| | | private int parkNums; |
| | | |
| | | @ApiModelProperty(value = "站点经度") |
| | | private double stationLng; |
| | | |
| | | @ApiModelProperty(value = "站点纬度") |
| | | private double stationLat; |
| | | |
| | | @ApiModelProperty(value = "站点引导") |
| | | private String siteGuide; |
| | | |
| | | @ApiModelProperty(value = "建设情况 1:居民区;\n" + |
| | | "2:公共机构;\n" + |
| | | "3:企事业单位;\n" + |
| | | "4:写字楼;\n" + |
| | | "5:工业园区; 6:交通枢纽;\n" + |
| | | "7:大型文体设施; 8:城市绿地;\n" + |
| | | "9:大型建筑配建停车场; 10:路边停车位;\n" + |
| | | "11:城际高速服务区; 255:其他") |
| | | private int construction; |
| | | |
| | | @ApiModelProperty(value = "匹配车型") |
| | | private String matchCars; |
| | | |
| | | @ApiModelProperty(value = "停车场信息") |
| | | private String parkInfo; |
| | | |
| | | @ApiModelProperty(value = "营业时间") |
| | | private String busineHours; |
| | | |
| | | @ApiModelProperty(value = "电费价格说明") |
| | | private String electricityFee; |
| | | |
| | | @ApiModelProperty(value = "服务费价格说明") |
| | | private String serviceFee; |
| | | |
| | | @ApiModelProperty(value = "停车费价格说明") |
| | | private String parkFee; |
| | | |
| | | @ApiModelProperty(value = "支付方式") |
| | | private String payment; |
| | | |
| | | @ApiModelProperty(value = "是否支持预约") |
| | | private int supportOrder; |
| | | |
| | | @ApiModelProperty(value = "备注") |
| | | private String remark; |
| | | @ApiModelProperty(value = "图片") |
| | | private List<String> pictures; |
| | | @ApiModelProperty(value = "快充总数") |
| | | private Integer fastTotal; |
| | | @ApiModelProperty(value = "快充数量") |
| | | private Integer fast; |
| | | @ApiModelProperty(value = "慢充数量") |
| | | private Integer snow; |
| | | @ApiModelProperty(value = "慢充总数") |
| | | private Integer snowTotal; |
| | | |
| | | @ApiModelProperty(value = "设备信息列表") |
| | | private List<EquipmentInfos> equipmentInfos; |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @ApiModel(description = "查询业务策略信息") |
| | | @Data |
| | | public class SupportOrder { |
| | | |
| | | @ApiModelProperty(value = "设备业务序列号", example = "123456789201805081628123456") |
| | | private String EquipBizSeq; |
| | | |
| | | @ApiModelProperty(value = "连接器ID", example = "3702120244401") |
| | | private String ConnectorID; |
| | | |
| | | @ApiModelProperty(value = "成功状态", example = "0") |
| | | private int SuccStat; |
| | | |
| | | @ApiModelProperty(value = "失败原因", example = "0") |
| | | private int FailReason; |
| | | |
| | | @ApiModelProperty(value = "总周期", example = "15") |
| | | private int SumPeriod; |
| | | |
| | | @ApiModelProperty(value = "策略信息列表") |
| | | private List<PolicyInfo> PolicyInfos; |
| | | |
| | | // Getters and Setters |
| | | |
| | | public String getEquipBizSeq() { |
| | | return EquipBizSeq; |
| | | } |
| | | |
| | | public void setEquipBizSeq(String equipBizSeq) { |
| | | EquipBizSeq = equipBizSeq; |
| | | } |
| | | |
| | | public String getConnectorID() { |
| | | return ConnectorID; |
| | | } |
| | | |
| | | public void setConnectorID(String connectorID) { |
| | | ConnectorID = connectorID; |
| | | } |
| | | |
| | | public int getSuccStat() { |
| | | return SuccStat; |
| | | } |
| | | |
| | | public void setSuccStat(int succStat) { |
| | | SuccStat = succStat; |
| | | } |
| | | |
| | | public int getFailReason() { |
| | | return FailReason; |
| | | } |
| | | |
| | | public void setFailReason(int failReason) { |
| | | FailReason = failReason; |
| | | } |
| | | |
| | | public int getSumPeriod() { |
| | | return SumPeriod; |
| | | } |
| | | |
| | | public void setSumPeriod(int sumPeriod) { |
| | | SumPeriod = sumPeriod; |
| | | } |
| | | |
| | | public List<PolicyInfo> getPolicyInfos() { |
| | | return PolicyInfos; |
| | | } |
| | | |
| | | public void setPolicyInfos(List<PolicyInfo> policyInfos) { |
| | | PolicyInfos = policyInfos; |
| | | } |
| | | |
| | | // Inner class for PolicyInfo |
| | | @ApiModel(description = "策略信息") |
| | | public static class PolicyInfo { |
| | | @ApiModelProperty(value = "开始时间", example = "090000") |
| | | private String StartTime; |
| | | |
| | | @ApiModelProperty(value = "电价", example = "0.5000") |
| | | private String ElecPrice; |
| | | |
| | | @ApiModelProperty(value = "服务费", example = "0.4000") |
| | | private String SevicePrice; |
| | | |
| | | // Getters and Setters |
| | | |
| | | public String getStartTime() { |
| | | return StartTime; |
| | | } |
| | | |
| | | public void setStartTime(String startTime) { |
| | | StartTime = startTime; |
| | | } |
| | | |
| | | public String getElecPrice() { |
| | | return ElecPrice; |
| | | } |
| | | |
| | | public void setElecPrice(String elecPrice) { |
| | | ElecPrice = elecPrice; |
| | | } |
| | | |
| | | public String getSevicePrice() { |
| | | return SevicePrice; |
| | | } |
| | | |
| | | public void setSevicePrice(String sevicePrice) { |
| | | SevicePrice = sevicePrice; |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * <p> |
| | | * 部门表 |
| | | * </p> |
| | | * |
| | | * @author stylefeng |
| | | * @since 2017-07-11 |
| | | */ |
| | | @TableName("t_content") |
| | | @Data |
| | | public class TContent extends Model<TContent> { |
| | | private static final long serialVersionUID = 1L; |
| | | /** |
| | | * 主键id |
| | | */ |
| | | @TableId(value="id", type= IdType.AUTO) |
| | | private Integer id; |
| | | /** |
| | | * 类型1推送订单结束 2结束充电 3请求充电 4特来电请求token 5推送订单状态 |
| | | */ |
| | | private Integer type; |
| | | /** |
| | | * 内容 |
| | | */ |
| | | private String content; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private Date createTime; |
| | | |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.service; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.TContent; |
| | | |
| | | public interface IContentService extends IService<TContent> { |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.chargingPile.tulaidian.dao.ContentMapper; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.TContent; |
| | | import com.ruoyi.chargingPile.tulaidian.service.IContentService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service |
| | | public class ContentServiceImpl extends ServiceImpl<ContentMapper, TContent> implements IContentService { |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.spec.IvParameterSpec; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | import java.util.Base64; |
| | | |
| | | /** |
| | | * 充电桩交互的数据的加密解密 |
| | | */ |
| | | public class AesEncryption { |
| | | |
| | | /** |
| | | * 加密 |
| | | * @param key |
| | | * @param iv |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public static String encrypt(String key, String iv, String data) { |
| | | try { |
| | | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
| | | SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES"); |
| | | IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes()); |
| | | cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); |
| | | byte[] encrypted = cipher.doFinal(data.getBytes()); |
| | | return Base64.getEncoder().encodeToString(encrypted); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 解密 |
| | | * @param key |
| | | * @param iv |
| | | * @param encryptedData |
| | | * @return |
| | | */ |
| | | public static String decrypt(String key, String iv, String encryptedData) { |
| | | try { |
| | | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
| | | SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES"); |
| | | IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes()); |
| | | cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); |
| | | byte[] decrypted = cipher.doFinal(Base64.getDecoder().decode(encryptedData)); |
| | | return new String(decrypted); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.chargingPile.tulaidian.constant.ChargePileInterface; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 通用http发送方法 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Component |
| | | public class ChargePileHttpUtil{ |
| | | |
| | | private static final String OperatorID = "MA01H3BQ3"; |
| | | private static final String OperatorSecret = "f1331ef0b37c2d2"; |
| | | private static final String SigSecret = "a6fedf0e1b27d6f8"; |
| | | private static final String DataSecret = "50a61b93919c9606"; |
| | | private static final String DataSecretIV = "7c8ac6861661d586"; |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | /** |
| | | * 验签 |
| | | * @return |
| | | */ |
| | | public static boolean checkSig(){ |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 获取token |
| | | * @return |
| | | */ |
| | | public String getToken(){ |
| | | String token = redisService.getCacheObject(ChargePileInterface.TOKEN_KEY); |
| | | if(StringUtils.hasLength(token)){ |
| | | return token; |
| | | } |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("OperatorSecret", OperatorSecret); |
| | | String params = jsonObject.toJSONString(); |
| | | // 参数加密 |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_TOKEN, jsonObject.toJSONString()); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | JSONObject tokenResult = JSONObject.parseObject(decrypt); |
| | | token = tokenResult.getString("AccessToken"); |
| | | Integer TokenAvailableTime = tokenResult.getInteger("TokenAvailableTime"); |
| | | redisService.setCacheObject(ChargePileInterface.TOKEN_KEY,token,Long.valueOf(TokenAvailableTime)-60L, TimeUnit.SECONDS); |
| | | return token; |
| | | } |
| | | |
| | | /** |
| | | * 获取充电桩 |
| | | * @return |
| | | */ |
| | | public String queryStationsInfo(Integer PageNo, Integer PageSize){ |
| | | String token = getToken(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("PageNo", PageNo); |
| | | jsonObject.put("PageSize", PageSize); |
| | | String params = jsonObject.toJSONString(); |
| | | // 参数加密 |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_STATIONS_INFO, jsonObject.toJSONString(),token); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | System.err.println(decrypt); |
| | | return decrypt; |
| | | } |
| | | |
| | | /** |
| | | * 获取充电桩 |
| | | * @return |
| | | */ |
| | | public String queryStationStatus(List<String> StationIDs){ |
| | | String token = getToken(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("StationIDs", StationIDs); |
| | | String params = jsonObject.toJSONString(); |
| | | // 参数加密 |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_STATION_STATUS, jsonObject.toJSONString(),token); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | System.err.println(decrypt); |
| | | return decrypt; |
| | | } |
| | | |
| | | /** |
| | | * 请求设备认证 |
| | | * @param EquipAuthSeq 设备认证流水号 格式“运营商ID+唯一编号”,27字符 |
| | | * @param ConnectorID 充电设备接口编码 格式“6位行政区编码,4位电站编码,3位终端编码”,13位字符 |
| | | * @return |
| | | */ |
| | | public String queryEquipAuth(String EquipAuthSeq,String ConnectorID){ |
| | | String token = getToken(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("EquipAuthSeq", EquipAuthSeq); |
| | | jsonObject.put("ConnectorID", ConnectorID); |
| | | String params = jsonObject.toJSONString(); |
| | | // 参数加密 |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_EQUIP_AUTH, jsonObject.toJSONString(),token); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | System.err.println(decrypt); |
| | | return decrypt; |
| | | } |
| | | |
| | | /** |
| | | * 请求充电 |
| | | * @param StartChargeSeq 充电订单号 格式“运营商ID+唯一编号”,27字符 |
| | | * @param ConnectorID 充电设备接口编码 格式“6位行政区编码,4位电站编码,3位终端编码”,13位字符 |
| | | * @param QRCode 二维码其他信息 二维码中含有自定义部分的,需要将二维码自定义部分的原文传输。 |
| | | * @param PhoneNum 手机号 个人支付必传,格式确保正确 |
| | | * @param PlateNum 车牌号 停车减免必传,格式确保正确 |
| | | * @return |
| | | */ |
| | | public String queryStartCharge(String StartChargeSeq,String ConnectorID,String QRCode,String PhoneNum,String PlateNum,BigDecimal money){ |
| | | String token = getToken(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("StartChargeSeq", StartChargeSeq); |
| | | jsonObject.put("ConnectorID", ConnectorID); |
| | | jsonObject.put("QRCode", QRCode); |
| | | jsonObject.put("PhoneNum", PhoneNum); |
| | | jsonObject.put("PlateNum", PlateNum); |
| | | jsonObject.put("chargingAmt", money); |
| | | String params = jsonObject.toJSONString(); |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_START_CHARGE, jsonObject.toJSONString(),token); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | System.err.println(decrypt); |
| | | return decrypt; |
| | | } |
| | | |
| | | /** |
| | | * 请求停止充电 |
| | | * @param StartChargeSeq 充电订单号 格式“运营商ID+唯一编号”,27字符 |
| | | * @param ConnectorID 充电设备接口编码 格式“6位行政区编码,4位电站编码,3位终端编码”,13位字符 |
| | | * @return |
| | | */ |
| | | public String queryStopCharge(String StartChargeSeq,String ConnectorID){ |
| | | String token = getToken(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("StartChargeSeq", StartChargeSeq); |
| | | jsonObject.put("ConnectorID", ConnectorID); |
| | | String params = jsonObject.toJSONString(); |
| | | // 参数加密 |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_STOP_CHARGE, jsonObject.toJSONString(),token); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | System.err.println(decrypt); |
| | | return decrypt; |
| | | } |
| | | /** |
| | | * 查询订单状态 |
| | | */ |
| | | public String queryEquipChargeStatus(String StartChargeSeq){ |
| | | String token = getToken(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("StartChargeSeq", StartChargeSeq); |
| | | String params = jsonObject.toJSONString(); |
| | | // 参数加密 |
| | | String data = AesEncryption.encrypt(DataSecret, DataSecretIV, params); |
| | | // 获取签名 |
| | | String timeStamp = System.currentTimeMillis() + ""; |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | String nextSequence = generator.getNextSequence(); |
| | | String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,SigSecret); |
| | | jsonObject = new JSONObject(); |
| | | jsonObject.put("OperatorID", OperatorID); |
| | | jsonObject.put("Data", data); |
| | | jsonObject.put("TimeStamp", timeStamp); |
| | | jsonObject.put("Seq", nextSequence); |
| | | jsonObject.put("Sig", hmacMD5); |
| | | String result = HttpUtils.sendPost(ChargePileInterface.QUERY_EQUIP_CHARGE_STATUS, jsonObject.toJSONString(),token); |
| | | String string = JSONObject.parseObject(result).getString("Data"); |
| | | String decrypt = AesEncryption.decrypt(DataSecret, DataSecretIV, string); |
| | | System.err.println(decrypt); |
| | | return decrypt; |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | |
| | | /** |
| | | * @Description |
| | | * @Author xiaochen |
| | | * @Date 2021/7/28 10:26 |
| | | */ |
| | | public class CodeGenerateUtils { |
| | | |
| | | /** |
| | | * @return |
| | | * @Description 获取商品编码 |
| | | * 商品编码规则:nanoTime(后5位)*5位随机数(10000~99999) |
| | | * @Author xiaochen |
| | | */ |
| | | public static String generateProductCode() { |
| | | long nanoPart = System.nanoTime() % 100000L; |
| | | if (nanoPart < 10000L) { |
| | | nanoPart += 10000L; |
| | | } |
| | | long randomPart = (long) (Math.random() * (90000) + 10000); |
| | | String code = "0" + new BigDecimal(nanoPart).multiply(new BigDecimal(randomPart)); |
| | | return code.substring(code.length() - 10); |
| | | } |
| | | |
| | | /** |
| | | * @return |
| | | * @Description 生成订单编号 10位 |
| | | * 订单编号规则:(10位):(年末尾*月,取后2位)+(用户ID%3.33*日取整后2位)+(timestamp*10000以内随机数,取后6位) |
| | | * @Author xiaochen |
| | | */ |
| | | public static String generateOrderSn() { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int year = calendar.get(Calendar.YEAR); |
| | | year = year % 10; |
| | | if (year == 0) year = 10; |
| | | int month = calendar.get(Calendar.MONTH) + 1; |
| | | int yearMonth = year * month; |
| | | String yearMonthPart = "0" + yearMonth; |
| | | yearMonthPart = yearMonthPart.substring(yearMonthPart.length() - 2); |
| | | |
| | | int day = calendar.get(Calendar.DAY_OF_MONTH); |
| | | double v = Math.random() * 10000; |
| | | int dayNum = (int) ((v % 3.33) * day); |
| | | String dayPart = "0" + dayNum; |
| | | dayPart = dayPart.substring(dayPart.length() - 2); |
| | | |
| | | String timestampPart = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000); |
| | | timestampPart = timestampPart.replace(".", "").replace("E", ""); |
| | | timestampPart = timestampPart.substring(0, 5); |
| | | return yearMonthPart + dayPart + timestampPart; |
| | | } |
| | | |
| | | /** |
| | | * @return |
| | | * @Description 生成统一支付单号 规则:年(2)月(2)日(2)时(2)分(2)+timestamp*5位随机整数取后5位 |
| | | * @Author xiaochen |
| | | */ |
| | | public static String generateVolumeSn() { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss"); |
| | | String dateTime = dateFormat.format(calendar.getTime()); |
| | | dateTime = dateTime.substring(2); |
| | | String timestampPart = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000); |
| | | timestampPart = timestampPart.replace(".", "").replace("E", ""); |
| | | timestampPart = timestampPart.substring(0, 6); |
| | | return dateTime + timestampPart; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.err.println(generateVolumeSn()); |
| | | } |
| | | |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | |
| | | public class HMacMD5Util { |
| | | |
| | | /** |
| | | * 加签 |
| | | * @param operatorId |
| | | * @param timeStamp |
| | | * @param data |
| | | * @param seq |
| | | * @param SigSecret |
| | | * @return |
| | | */ |
| | | public static String getHMacMD5(String operatorId,String timeStamp, String data, String seq,String SigSecret) { |
| | | String m = new StringBuilder(operatorId).append(data).append(timeStamp).append(seq).toString(); |
| | | byte[] macMD5 = HMacMD5Util.getHMacMD5Bytes(SigSecret.getBytes(), m.getBytes()); |
| | | return HMacMD5Util.bytesToHexString(macMD5); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * HmacMd5的计算公式为:HMAC(K,M) = H(K⊕opad∣H(K⊕ipad∣M)) |
| | | * 其中:K是密钥(byte[] key),长度可为64字节(后面涉及描述都是以字节byte进行),若小于该长度,在密钥后面用0(即0x00)补齐。 |
| | | * M是消息内容(byte[] m); |
| | | * H是散列函数(此处采用MD5); |
| | | * opad和ipad分别是由若干个0x5c和0x36组成的字符串; |
| | | * ⊕表示异或运算; |
| | | * ∣表示连接操作。 |
| | | **/ |
| | | private static byte[] getHMacMD5Bytes(byte[] key, byte[] m) { |
| | | try { |
| | | //定义长度 |
| | | int length = 64; |
| | | //定义opad和ipad |
| | | byte[] opad = new byte[length]; |
| | | byte[] ipad = new byte[length]; |
| | | for (int i = 0; i < 64; i++) { |
| | | opad[i] = 0x5C; |
| | | ipad[i] = 0x36; |
| | | } |
| | | byte[] actualKey = key; |
| | | byte[] keyArr = new byte[length]; |
| | | //如果密钥长度,大于64字节,就使用MD5算法计算其散列值,作为密钥 |
| | | if (key.length > length) { |
| | | actualKey = md5(key); |
| | | } |
| | | for (int i = 0; i < actualKey.length; i++) { |
| | | keyArr[i] = actualKey[i]; |
| | | } |
| | | //如果密钥长度不足64字节,就使用0x00补齐到64字节 |
| | | if (actualKey.length < length) { |
| | | for (int i = key.length; i < length; i++) |
| | | keyArr[i] = 0x00; |
| | | } |
| | | //使用密钥和ipad进行异或运算【K⊕ipad】 |
| | | byte[] kIpadXorResult = new byte[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | kIpadXorResult[i] = (byte) (keyArr[i] ^ ipad[i]); |
| | | } |
| | | //将待加密数据M追加到kIpadXorResult后面【K⊕ipad∣M】 |
| | | byte[] firstAppendResult = new byte[kIpadXorResult.length + m.length]; |
| | | for (int i = 0; i < kIpadXorResult.length; i++) { |
| | | firstAppendResult[i] = kIpadXorResult[i]; |
| | | } |
| | | for (int i = 0; i < m.length; i++) { |
| | | firstAppendResult[i + keyArr.length] = m[i]; |
| | | } |
| | | //做MD5运算【H(K⊕ipad∣M)】 |
| | | byte[] firstHashResult = md5(firstAppendResult); |
| | | |
| | | //使用密钥和opad进行异或运算【K⊕opad】 |
| | | byte[] kOpadXorResult = new byte[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | kOpadXorResult[i] = (byte) (keyArr[i] ^ opad[i]); |
| | | } |
| | | //将firstHashResult追加到kOpadXorResult后面【K⊕opad∣H(K⊕ipad∣M)】 |
| | | byte[] secondAppendResult = new byte[kOpadXorResult.length + firstHashResult.length]; |
| | | for (int i = 0; i < kOpadXorResult.length; i++) { |
| | | secondAppendResult[i] = kOpadXorResult[i]; |
| | | } |
| | | for (int i = 0; i < firstHashResult.length; i++) { |
| | | secondAppendResult[kOpadXorResult.length + i] = firstHashResult[i]; |
| | | } |
| | | //做MD5运算【H(K⊕opad∣H(K⊕ipad∣M))】 |
| | | return md5(secondAppendResult); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * MD5(产生出一个128位(16字节)的散列值) |
| | | **/ |
| | | private static byte[] md5(byte[] str) throws NoSuchAlgorithmException { |
| | | MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | md.update(str); |
| | | return md.digest(); |
| | | } |
| | | |
| | | /** |
| | | * HEX转化为字符串 |
| | | **/ |
| | | private static String bytesToHexString(byte[] m) { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | if (m == null || m.length <= 0) { |
| | | return null; |
| | | } |
| | | for (int i = 0; i < m.length; i++) { |
| | | int v = m[i] & 0xFF; |
| | | String hv = Integer.toHexString(v); |
| | | if (hv.length() < 2) { |
| | | stringBuilder.append(0); |
| | | } |
| | | stringBuilder.append(hv); |
| | | } |
| | | return stringBuilder.toString().toUpperCase(); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import javax.net.ssl.*; |
| | | import java.io.*; |
| | | import java.net.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.cert.X509Certificate; |
| | | |
| | | /** |
| | | * 通用http发送方法 |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | public class HttpUtils |
| | | { |
| | | private static final Logger log = LoggerFactory.getLogger(HttpUtils.class); |
| | | |
| | | /** |
| | | * 向指定 URL 发送GET方法的请求 |
| | | * |
| | | * @param url 发送请求的 URL |
| | | * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
| | | * @param contentType 编码类型 |
| | | * @return 所代表远程资源的响应结果 |
| | | */ |
| | | public static String sendGet(String url, String param, String contentType) |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | BufferedReader in = null; |
| | | try |
| | | { |
| | | String urlNameString = StringUtils.isNotEmpty(param) ? url + "?" + param : url; |
| | | log.info("sendGet - {}", urlNameString); |
| | | URL realUrl = new URL(urlNameString); |
| | | URLConnection connection = realUrl.openConnection(); |
| | | connection.setRequestProperty("accept", "*/*"); |
| | | connection.setRequestProperty("connection", "Keep-Alive"); |
| | | connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | connection.connect(); |
| | | in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType)); |
| | | String line; |
| | | while ((line = in.readLine()) != null) |
| | | { |
| | | result.append(line); |
| | | } |
| | | log.info("recv - {}", result); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("调用HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (in != null) |
| | | { |
| | | in.close(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.error("调用in.close Exception, url=" + url + ",param=" + param, ex); |
| | | } |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 向指定 URL 发送POST方法的请求 |
| | | * |
| | | * @param url 发送请求的 URL |
| | | * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
| | | * @return 所代表远程资源的响应结果 |
| | | */ |
| | | public static String sendPost(String url, String param) |
| | | { |
| | | PrintWriter out = null; |
| | | BufferedReader in = null; |
| | | StringBuilder result = new StringBuilder(); |
| | | try |
| | | { |
| | | log.info("sendPost - {}", url); |
| | | URL realUrl = new URL(url); |
| | | URLConnection conn = realUrl.openConnection(); |
| | | conn.setRequestProperty("accept", "*/*"); |
| | | conn.setRequestProperty("connection", "Keep-Alive"); |
| | | conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | conn.setRequestProperty("Accept-Charset", "utf-8"); |
| | | conn.setRequestProperty("Content-Type", "application/json"); |
| | | conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | | out = new PrintWriter(conn.getOutputStream()); |
| | | out.print(param); |
| | | out.flush(); |
| | | in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); |
| | | String line; |
| | | while ((line = in.readLine()) != null) |
| | | { |
| | | result.append(line); |
| | | } |
| | | log.info("recv - {}", result); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (out != null) |
| | | { |
| | | out.close(); |
| | | } |
| | | if (in != null) |
| | | { |
| | | in.close(); |
| | | } |
| | | } |
| | | catch (IOException ex) |
| | | { |
| | | log.error("调用in.close Exception, url=" + url + ",param=" + param, ex); |
| | | } |
| | | } |
| | | return result.toString(); |
| | | } |
| | | /** |
| | | * 向指定 URL 发送POST方法的请求 |
| | | * |
| | | * @param url 发送请求的 URL |
| | | * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
| | | * @param token token |
| | | * @return 所代表远程资源的响应结果 |
| | | */ |
| | | public static String sendPost(String url, String param,String token) |
| | | { |
| | | PrintWriter out = null; |
| | | BufferedReader in = null; |
| | | StringBuilder result = new StringBuilder(); |
| | | try |
| | | { |
| | | log.info("sendPost - {}", url); |
| | | URL realUrl = new URL(url); |
| | | URLConnection conn = realUrl.openConnection(); |
| | | conn.setRequestProperty("accept", "*/*"); |
| | | conn.setRequestProperty("connection", "Keep-Alive"); |
| | | conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | conn.setRequestProperty("Accept-Charset", "utf-8"); |
| | | conn.setRequestProperty("Content-Type", "application/json"); |
| | | conn.setRequestProperty("Authorization", "Bearer "+token); |
| | | conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | | out = new PrintWriter(conn.getOutputStream()); |
| | | out.print(param); |
| | | out.flush(); |
| | | in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); |
| | | String line; |
| | | while ((line = in.readLine()) != null) |
| | | { |
| | | result.append(line); |
| | | } |
| | | log.info("recv - {}", result); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (out != null) |
| | | { |
| | | out.close(); |
| | | } |
| | | if (in != null) |
| | | { |
| | | in.close(); |
| | | } |
| | | } |
| | | catch (IOException ex) |
| | | { |
| | | log.error("调用in.close Exception, url=" + url + ",param=" + param, ex); |
| | | } |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | public static String sendSSLPost(String url, String param) |
| | | { |
| | | StringBuilder result = new StringBuilder(); |
| | | String urlNameString = url + "?" + param; |
| | | try |
| | | { |
| | | log.info("sendSSLPost - {}", urlNameString); |
| | | SSLContext sc = SSLContext.getInstance("SSL"); |
| | | sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom()); |
| | | URL console = new URL(urlNameString); |
| | | HttpsURLConnection conn = (HttpsURLConnection) console.openConnection(); |
| | | conn.setRequestProperty("accept", "*/*"); |
| | | conn.setRequestProperty("connection", "Keep-Alive"); |
| | | conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | conn.setRequestProperty("Accept-Charset", "utf-8"); |
| | | conn.setRequestProperty("contentType", "utf-8"); |
| | | conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | | |
| | | conn.setSSLSocketFactory(sc.getSocketFactory()); |
| | | conn.setHostnameVerifier(new TrustAnyHostnameVerifier()); |
| | | conn.connect(); |
| | | InputStream is = conn.getInputStream(); |
| | | BufferedReader br = new BufferedReader(new InputStreamReader(is)); |
| | | String ret = ""; |
| | | while ((ret = br.readLine()) != null) |
| | | { |
| | | if (ret != null && !"".equals(ret.trim())) |
| | | { |
| | | result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)); |
| | | } |
| | | } |
| | | log.info("recv - {}", result); |
| | | conn.disconnect(); |
| | | br.close(); |
| | | } |
| | | catch (ConnectException e) |
| | | { |
| | | log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (SocketTimeoutException e) |
| | | { |
| | | log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e); |
| | | } |
| | | return result.toString(); |
| | | } |
| | | |
| | | public static String post(String strURL, String params) { |
| | | String result = ""; |
| | | BufferedReader reader = null; |
| | | try { |
| | | URL url = new URL(strURL);// 创建连接 |
| | | HttpURLConnection connection = (HttpURLConnection) url |
| | | .openConnection(); |
| | | connection.setDoOutput(true); |
| | | connection.setDoInput(true); |
| | | connection.setUseCaches(false); |
| | | connection.setInstanceFollowRedirects(true); |
| | | connection.setRequestMethod("POST"); // 设置请求方式 |
| | | connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式 |
| | | connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式 |
| | | connection.connect(); |
| | | if (params != null && !StringUtils.isEmpty(params)) { |
| | | byte[] writebytes = params.getBytes(); |
| | | // 设置文件长度 |
| | | // connection.setRequestProperty("Content-Length", String.valueOf(writebytes.length)); |
| | | OutputStream outwritestream = connection.getOutputStream(); |
| | | outwritestream.write(params.getBytes()); |
| | | outwritestream.flush(); |
| | | outwritestream.close(); |
| | | // Log.d("hlhupload", "doJsonPost: conn"+connection.getResponseCode()); |
| | | } |
| | | if (connection.getResponseCode() == 200) { |
| | | log.info("<<<<<<<<<<<<<请求响应:{}", connection.getResponseMessage()); |
| | | reader = new BufferedReader( |
| | | new InputStreamReader(connection.getInputStream())); |
| | | result = reader.readLine(); |
| | | log.info("<<<<<<<<<<<<<请求响应:{}", result); |
| | | } else { |
| | | throw new ServiceException(connection.getResponseMessage()); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new ServiceException("http的post请求异常!" + e.getMessage()); |
| | | } finally { |
| | | if (reader != null) { |
| | | try { |
| | | reader.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private static class TrustAnyTrustManager implements X509TrustManager |
| | | { |
| | | @Override |
| | | public void checkClientTrusted(X509Certificate[] chain, String authType) |
| | | { |
| | | } |
| | | |
| | | @Override |
| | | public void checkServerTrusted(X509Certificate[] chain, String authType) |
| | | { |
| | | } |
| | | |
| | | @Override |
| | | public X509Certificate[] getAcceptedIssuers() |
| | | { |
| | | return new X509Certificate[] {}; |
| | | } |
| | | } |
| | | |
| | | private static class TrustAnyHostnameVerifier implements HostnameVerifier |
| | | { |
| | | @Override |
| | | public boolean verify(String hostname, SSLSession session) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | public class SequenceGenerator { |
| | | private final ConcurrentHashMap<Long, AtomicInteger> counterMap = new ConcurrentHashMap<>(); |
| | | |
| | | public synchronized String getNextSequence() { |
| | | long currentTimestamp = System.currentTimeMillis() / 1000; // 获取当前秒级时间戳 |
| | | |
| | | AtomicInteger counter = counterMap.get(currentTimestamp); |
| | | if (counter == null) { |
| | | counter = new AtomicInteger(1); // 新的一秒,初始化计数器为1 |
| | | counterMap.put(currentTimestamp, counter); |
| | | } else { |
| | | counter.incrementAndGet(); // 同一秒内,计数器递增 |
| | | } |
| | | |
| | | // 生成四位序列号 |
| | | String sequence = String.format("%04d", counter.get()); |
| | | |
| | | return sequence; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | SequenceGenerator generator = new SequenceGenerator(); |
| | | |
| | | // 测试生成多个序列号 |
| | | for (int i = 0; i < 10; i++) { |
| | | System.out.println(generator.getNextSequence()); |
| | | try { |
| | | Thread.sleep(100); // 模拟同一秒内的多次调用 |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 模拟进入新的一秒 |
| | | try { |
| | | Thread.sleep(1100); // 等待超过1秒 |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // 再次生成序列号 |
| | | for (int i = 0; i < 10; i++) { |
| | | System.out.println(generator.getNextSequence()); |
| | | try { |
| | | Thread.sleep(100); // 模拟同一秒内的多次调用 |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.chargingPile.tulaidian.util; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.chargingPile.tulaidian.domain.ChargeStatus; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderClient; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | | * @date 2023/6/24 15:26 |
| | | */ |
| | | @Component |
| | | public class TaskUtilCharging { |
| | | @Autowired |
| | | private ChargingOrderClient chargingOrderClient; |
| | | @Autowired |
| | | private ChargePileHttpUtil chargePileHttpUtil; |
| | | /** |
| | | * 每隔一分钟去处理的定时任务 |
| | | */ |
| | | // @Scheduled(fixedRate = 1000 * 60) |
| | | // public void taskMinute() { |
| | | // try { |
| | | // List<Integer> statusList = new ArrayList<>(); |
| | | // R<List<TChargingOrder>> statusR = chargingOrderClient.getOrderListByStatus(statusList); |
| | | // List<TChargingOrder> status = statusR.getData(); |
| | | // if(!CollectionUtils.isEmpty(status)){ |
| | | // for (TChargingOrder chargeOrder : status) { |
| | | // String s = chargePileHttpUtil.queryEquipChargeStatus(chargeOrder.getStartChargeSeq()); |
| | | // System.out.println("充电订单:"+chargeOrder.getCode()+"充电状态:"+s); |
| | | // JSONObject jsonObject = JSONObject.parseObject(s); |
| | | // ChargeStatus chargeStatus = JSON.parseObject(jsonObject.toJSONString(), ChargeStatus.class); |
| | | // chargeOrder.setStatus(chargeStatus.getStartChargeSeqStat()); |
| | | // chargingOrderClient.updateChargingOrder(chargeOrder); |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | } |
| | |
| | | |
| | | return R.ok(new BigDecimal(sumDegreeBySiteIds)); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/addChargingOrder") |
| | | public R<Long> addChargingOrder(@RequestBody TChargingOrder chargingOrder){ |
| | | chargingOrderService.save(chargingOrder); |
| | | return R.ok(chargingOrder.getId()); |
| | | } |
| | | |
| | | |
| | | @GetMapping(value = "/getOrderIdByUserId") |