| | |
| | | // 已完成 |
| | | COMPLETE(4), |
| | | |
| | | ; |
| | | //已取消 |
| | | CANCEL(-1);; |
| | | |
| | | private Integer status; |
| | | |
| | |
| | | HttpServletRequest request = RequestHolder.getHttpServletRequest(); |
| | | return ServletUtil.getClientIP(request); |
| | | } |
| | | |
| | | public static String getIpAddr(HttpServletRequest request) { |
| | | String ip = request.getHeader("x-forwarded-for"); |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getHeader("Proxy-Client-IP"); |
| | | } |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getHeader("WL-Proxy-Client-IP"); |
| | | } |
| | | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip = request.getRemoteAddr(); |
| | | } |
| | | return ip; |
| | | } |
| | | |
| | | } |
| | |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.SortedMap; |
| | | |
| | |
| | | */ |
| | | @AnonymousAccess |
| | | @PostMapping("/advancePay") |
| | | public ResponseVO<Object> advancePayOrder(@RequestBody PayParam param) throws WxErrorException { |
| | | public ResponseVO<Object> advancePayOrder(HttpServletRequest request, @RequestBody PayParam param) throws WxErrorException { |
| | | if (param.getOpenId().isEmpty()) { |
| | | throw new BusinessException("微信code不能为空"); |
| | | } |
| | |
| | | //生成订单 |
| | | C3mOrder c3mOrderEntity = c3mOrderService.advancePayOrder(param.getPoleId(), c3m, "wxpay" |
| | | , totalAmount, param.getSubscribeChargingCapacity(), param.getOpenId()); |
| | | if (null == c3mOrderEntity) { |
| | | throw new BusinessException("该充电桩正被使用!"); |
| | | } |
| | | |
| | | param.setOutTradeNo(c3mOrderEntity.getOutTradeNo()); |
| | | param.setTotalAmount(c3mOrderEntity.getTotalAmount()); |
| | | String s = WxFastPayService.parseWxAmount(param.getTotalAmount().toString()); |
| | | String s = WxFastPayService.parseWxAmount(c3mOrderEntity.getTotalAmount().toString()); |
| | | //生成微信预付订单 |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay("扫码充电支付(C3充电桩)", param.getOutTradeNo(), Integer.valueOf(s), param.getPoleId(), param.getOpenId()); |
| | | SortedMap<Object, Object> result = wxPayService.miniAppPay(request,"扫码充电支付(C3充电桩)", c3mOrderEntity.getOutTradeNo(), Integer.valueOf(s), param.getPoleId(), param.getOpenId()); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 清除任务 |
| | | * @param |
| | | * @return |
| | | */ |
| | | @PostMapping("/clear") |
| | | public ResponseVO<Object> clearLightTask(@RequestBody List<Long> poleIds) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_TASK_UPDATE.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean result = lightTaskService.clearLightTask(poleIds); |
| | | return ResponseUtil.success(result); |
| | | } |
| | | |
| | | @GetMapping("/{taskId}") |
| | | public ResponseVO<Object> detailLightTask(@PathVariable Long taskId) { |
| | | if (!permissionConfig.check(MenuEnum.LIGHT_TASK_DETAIL.getCode())) { |
| | |
| | | private String c3Mac; |
| | | //灯杆ID |
| | | private Long poleId; |
| | | //充电桩桩状态 |
| | | //充电桩桩状态 1.空闲 2.充电中 3.充电中断,等待服务器确认 4.充电结束,等待服务器确认 5.有故障 6.与充电桩对接中 |
| | | private Integer statusBit; |
| | | //电压 |
| | | private String gridVoltage; |
| | |
| | | private String sec; |
| | | // 充电桩口 |
| | | private String chargingPort; |
| | | // 充电桩口状态位 |
| | | // 充电桩口状态位 1.空闲 2.充电中 3.充电中断,等待服务器确认 4.充电结束,等待服务器确认 5.有故障 6.与充电桩对接中 |
| | | private String statusBit; |
| | | // 设备温度 0.1℃ |
| | | private String deviceTemperature; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | * @return |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SortedMap<Object, Object> miniAppPay(String body, String orderId, int totalFee, Long poleId, String wxCode) throws WxErrorException { |
| | | public SortedMap<Object, Object> miniAppPay(HttpServletRequest request, String body, String orderId, int totalFee, Long poleId, String wxCode) throws WxErrorException { |
| | | WxConfigEntity wxConfig = wxPayConfigService.getConfigByPoleId(poleId); |
| | | |
| | | //设置微信支付参数 |
| | |
| | | |
| | | |
| | | wxPayUnifiedOrderRequest.setSignType(WxPayConstants.SignType.MD5); |
| | | wxPayUnifiedOrderRequest.setSpbillCreateIp(IpUtil.getRealIp()); |
| | | wxPayUnifiedOrderRequest.setSpbillCreateIp(IpUtil.getIpAddr(request)); |
| | | wxPayUnifiedOrderRequest.setNotifyUrl(WECHAT_ORDER_PAY_CALLBACK_URL); |
| | | wxPayUnifiedOrderRequest.setTradeType(WxPayConstants.TradeType.JSAPI); |
| | | System.out.println("-----------" + wxPayUnifiedOrderRequest); |
| | |
| | | SortedMap<Object, Object> parameters = new TreeMap<>(); |
| | | parameters.put("appid", wxPayUnifiedOrderResult.getAppid()); |
| | | |
| | | parameters.put("noncestr", wxPayUnifiedOrderResult.getNonceStr()); // 随机字符串 |
| | | // parameters.put("noncestr", wxPayUnifiedOrderResult.getNonceStr()); // 随机字符串 |
| | | parameters.put("partnerid", wxConfig.getMchId()); // 商户id |
| | | |
| | | // parameters.put("out_trade_no", orderId);//商户订单号 |
| | | parameters.put("prepayid", wxPayUnifiedOrderResult.getPrepayId()); |
| | | parameters.put("package", "Sign=WXPay"); |
| | | parameters.put("timestamp", time); |
| | | // parameters.put("package", "Sign=WXPay"); |
| | | // parameters.put("timestamp", time); |
| | | |
| | | String sign = createSign(wxConfig.getPrivateKey(), parameters); |
| | | |
| | |
| | | chargingDto.setC3Id(one.getC3Id()); |
| | | //C3Mac |
| | | chargingDto.setC3Mac(one.getC3Mac()); |
| | | //在线状态 |
| | | //在线状态 1.空闲 2.充电中 3.充电中断,等待服务器确认 4.充电结束,等待服务器确认 5.有故障 6.与充电桩对接中 |
| | | chargingDto.setStatusBit(Integer.valueOf(beatDataPackage.getStatusBit())); |
| | | //电压 |
| | | chargingDto.setGridVoltage(beatDataPackage.getGridVoltage()); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public C3mOrder advancePayOrder(Long streetlightId, C3mCharging c3m, String orderType, Double totalAmount, |
| | | Integer subscribeChargingCapacity, String wxCode) { |
| | | |
| | | // 判断该充电桩是否存在正在进行中的订单 |
| | | String chargingJson = redisUtils.get(C3mRedisConstant.C3_CHARGING_ORDER.getCode() + c3m.getC3Mac()); |
| | | if (null != chargingJson) { |
| | | throw new BusinessException("该充电桩已存在正在进行中的订单"); |
| | | } |
| | | //查询充电桩是否存在正在进行中的订单 |
| | | C3mOrder c3mOrder = getOne(Wrappers.lambdaQuery(C3mOrder.class) |
| | | .eq(C3mOrder::getC3Udid, c3m.getMcuUdid()).eq(C3mOrder::getChargingStates, 0).last("limit 1")); |
| | | .eq(C3mOrder::getC3Udid, c3m.getMcuUdid()).last("limit 1")); |
| | | |
| | | if (c3mOrder != null && !c3mOrder.getUserCode().equals(wxCode)) { |
| | | throw new BusinessException("该充电桩正在被别人使用"); |
| | | //充电桩正在充电中 |
| | | if (c3mOrder != null && c3mOrder.getChargingStates() == 0) { |
| | | throw new BusinessException("充电桩正在被占用!"); |
| | | } |
| | | |
| | | //存在订单,但是未支付,需要取消订单 |
| | | if (c3mOrder != null) { |
| | | throw new BusinessException("该充电桩已存在正在进行中的订单"); |
| | | c3mOrder.setOrderStatus(OrderStatus.CANCEL.getStatus()); |
| | | updateById(c3mOrder); |
| | | } |
| | | |
| | | Pole pole = poleService.getById(streetlightId); |
| | | if (null == pole) { |
| | | return null; |
| | | throw new BusinessException("充电桩灯杆信息不存在!"); |
| | | } |
| | | // 生成订单,并加载到redis缓存,设置超时时间为5分钟 |
| | | // 生成订单 |
| | | C3mOrder c3mOrderEntity = new C3mOrderVO().generateOrder( |
| | | streetlightId, |
| | | pole.getDeviceCode(), |
| | |
| | | totalAmount, |
| | | subscribeChargingCapacity |
| | | ); |
| | | boolean b = true; |
| | | c3mOrderEntity.setOrderId(snowflake.nextId()); |
| | | c3mOrderEntity.setC3Mac(c3m.getC3Name()); |
| | | c3mOrderEntity.setPoleId(streetlightId); |
| | |
| | | c3mOrderEntity.setUserCode(wxCode); |
| | | c3mOrderEntity.setC3Udid(c3m.getMcuUdid()); |
| | | |
| | | if (b) { |
| | | this.save(c3mOrderEntity); |
| | | // |
| | | c3mOrderEntity.setC3Name("创建订单"); |
| | | |
| | | |
| | | if (save(c3mOrderEntity)) { |
| | | return c3mOrderEntity; |
| | | } else { |
| | | throw new BusinessException("创建订单失败,请重新扫码!"); |
| | | } |
| | | return b ? c3mOrderEntity : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | String orderSn = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | String transactionId = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | C3mOrder userOrder = getByOrderSn(orderSn); |
| | | userOrder.setC3Name("回调成功"); |
| | | updateById(userOrder); |
| | | if (userOrder == null) { |
| | | return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn); |
| | | } |
| | |
| | | public void deleteOrderListByCreateTime() { |
| | | // 获取当前时间戳 |
| | | Long time = System.currentTimeMillis(); |
| | | |
| | | //当前时间减去10分钟 |
| | | Long timeMinus10 = time - 600000; |
| | | |
| | | //删除超过10分钟未付款的订单 |
| | | remove(Wrappers.lambdaQuery(C3mOrder.class).lt(C3mOrder::getCreateTimestamp, time).eq(C3mOrder::getOrderStatus, 0)); |
| | | remove(Wrappers.lambdaQuery(C3mOrder.class).lt(C3mOrder::getCreateTimestamp, timeMinus10).eq(C3mOrder::getOrderStatus, 0)); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | public boolean clearLightTask(List<Long> poleIds) { |
| | | Map<String, List<LightTaskPoleRelation>> ffff = sendControllerFrame(poleIds, "", "FFFF"); |
| | | ffff.get("success").forEach(lightTaskPoleRelation -> { |
| | | lightTaskPoleRelationService.remove(Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, lightTaskPoleRelation.getPoleId()).eq(LightTaskPoleRelation::getTaskId, lightTaskPoleRelation.getTaskId())); |
| | | }); |
| | | return true; |
| | | } |
| | | } |