| | |
| | | * @param notifyChargeOrderDto 数据对象分享 |
| | | * @return 小区下的小区楼记录数 |
| | | */ |
| | | @RequestMapping(value = "/heartbeat", method = RequestMethod.POST) |
| | | ResponseEntity<String> heartbeat(@RequestBody NotifyChargeOrderDto notifyChargeOrderDto); |
| | | @RequestMapping(value = "/workHeartbeat", method = RequestMethod.POST) |
| | | ResultVo workHeartbeat(@RequestBody NotifyChargeOrderDto notifyChargeOrderDto); |
| | | |
| | | |
| | | } |
| | |
| | | private INotifyChargeV1InnerServiceSMO notifyChargeV1InnerServiceSMOImpl; |
| | | |
| | | /** |
| | | * <p>支付回调Api</p> |
| | | * <p>充电结束通知</p> |
| | | * |
| | | * @param request |
| | | * @throws Exception |
| | |
| | | * @param request |
| | | * @throws Exception |
| | | */ |
| | | @RequestMapping(path = "/{id}/event", method = RequestMethod.POST) |
| | | public ResponseEntity<String> heartbeat( |
| | | @RequestMapping(path = "/{id}/power", method = RequestMethod.POST) |
| | | public ResponseEntity<String> workHeartbeat( |
| | | @PathVariable String id, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request) { |
| | | if (!validateSign(request, "/equipments/" + id + "/event", postInfo)) { |
| | | if (!validateSign(request, "/equipments/" + id + "/power", postInfo)) { |
| | | return new ResponseEntity<>("{\n" + |
| | | "\"code\" : -1,\n" + |
| | | "\"msg\" : \"鉴权失败\"\n" + |
| | | "}", HttpStatus.OK); |
| | | } |
| | | |
| | | JSONObject param = JSONObject.parseObject(postInfo); |
| | | NotifyChargeOrderDto notifyChargeOrderDto = new NotifyChargeOrderDto(); |
| | | notifyChargeOrderDto.setMachineCode(id); |
| | | notifyChargeOrderDto.setBodyParam(postInfo); |
| | | ResultVo resultVo = null; |
| | | resultVo = notifyChargeV1InnerServiceSMOImpl.workHeartbeat(notifyChargeOrderDto); |
| | | if (resultVo.getCode() == ResultVo.CODE_OK) { |
| | | resultVo.setCode(200); |
| | | resultVo.setMsg("success"); |
| | | } |
| | | |
| | | return notifyChargeV1InnerServiceSMOImpl.heartbeat(notifyChargeOrderDto); |
| | | |
| | | return ResultVo.createResponseEntity(resultVo); |
| | | } |
| | | |
| | | private boolean validateSign(HttpServletRequest request, String url, String postInfo) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResponseEntity<String> heartbeat(NotifyChargeOrderDto notifyChargeOrderDto) { |
| | | return new ResponseEntity<>("{\n" + |
| | | "\"code\" : 200,\n" + |
| | | "\"msg\" : \"success\"\n" + |
| | | "}", HttpStatus.OK); |
| | | public ResultVo workHeartbeat(NotifyChargeOrderDto notifyChargeOrderDto) { |
| | | |
| | | ChargeMachineDto chargeMachineDto = new ChargeMachineDto(); |
| | | chargeMachineDto.setMachineCode(notifyChargeOrderDto.getMachineCode()); |
| | | List<ChargeMachineDto> chargeMachineDtos = chargeMachineV1InnerServiceSMOImpl.queryChargeMachines(chargeMachineDto); |
| | | |
| | | if (chargeMachineDtos == null || chargeMachineDtos.size() < 1) { |
| | | return new ResultVo(ResultVo.CODE_OK, "成功"); |
| | | } |
| | | |
| | | |
| | | ChargeMachineFactoryDto chargeMachineFactoryDto = new ChargeMachineFactoryDto(); |
| | | chargeMachineFactoryDto.setFactoryId(chargeMachineDtos.get(0).getImplBean()); |
| | | List<ChargeMachineFactoryDto> chargeMachineFactoryDtos = chargeMachineFactoryV1InnerServiceSMOImpl.queryChargeMachineFactorys(chargeMachineFactoryDto); |
| | | |
| | | Assert.listOnlyOne(chargeMachineFactoryDtos, "充电桩厂家不存在"); |
| | | |
| | | IChargeFactoryAdapt chargeFactoryAdapt = ApplicationContextFactory.getBean(chargeMachineFactoryDtos.get(0).getBeanImpl(), IChargeFactoryAdapt.class); |
| | | if (chargeFactoryAdapt == null) { |
| | | throw new CmdException("厂家接口未实现"); |
| | | } |
| | | |
| | | chargeFactoryAdapt.workHeartbeat(chargeMachineDtos.get(0),notifyChargeOrderDto.getBodyParam()); |
| | | |
| | | return new ResultVo(ResultVo.CODE_OK, "成功"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | ResultVo finishCharge(NotifyChargeOrderDto notifyChargeOrderDto); |
| | | |
| | | ResponseEntity<String> heartbeat(NotifyChargeOrderDto notifyChargeOrderDto); |
| | | ResultVo workHeartbeat(NotifyChargeOrderDto notifyChargeOrderDto); |
| | | |
| | | |
| | | /** |
| | |
| | | * @param chargeMachineDto |
| | | */ |
| | | void queryChargeMachineState(ChargeMachineDto chargeMachineDto); |
| | | |
| | | /** |
| | | * 工作心跳 |
| | | * @param chargeMachineDto |
| | | * @param bodyParam |
| | | */ |
| | | void workHeartbeat(ChargeMachineDto chargeMachineDto, String bodyParam); |
| | | } |
| | |
| | | chargeMachineDto.setState(ChargeMachineDto.STATE_ONLINE); |
| | | chargeMachineDto.setStateName("在线"); |
| | | } |
| | | |
| | | @Override |
| | | public void workHeartbeat(ChargeMachineDto chargeMachineDto, String bodyParam) { |
| | | |
| | | } |
| | | } |
| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.charge.IChargeFactoryAdapt; |
| | | import com.java110.dto.chargeMachine.ChargeMachineDto; |
| | | import com.java110.dto.chargeMachineOrder.ChargeMachineOrderDto; |
| | | import com.java110.dto.chargeMachineOrder.NotifyChargeOrderDto; |
| | | import com.java110.dto.chargeMachineOrder.NotifyChargePortDto; |
| | | import com.java110.dto.chargeMachinePort.ChargeMachinePortDto; |
| | | import com.java110.intf.common.IChargeMachineOrderV1InnerServiceSMO; |
| | | import com.java110.po.chargeMachineOrder.ChargeMachineOrderPo; |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.vo.ResultVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | |
| | | //关闭充电 |
| | | private static final String STOP_CHARGE_URL = DingdingChargeUtils.URL + "/equipments/ID/PORT/close"; |
| | | |
| | | @Autowired |
| | | private IChargeMachineOrderV1InnerServiceSMO chargeMachineOrderV1InnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public ResultVo startCharge(ChargeMachineDto chargeMachineDto, ChargeMachinePortDto chargeMachinePortDto, String chargeType, double duration, String orderId) { |
| | |
| | | chargeMachineDto.setState(ChargeMachineDto.STATE_OFFLINE); |
| | | chargeMachineDto.setStateName("离线"); |
| | | } |
| | | |
| | | @Override |
| | | public void workHeartbeat(ChargeMachineDto chargeMachineDto, String bodyParam) { |
| | | |
| | | JSONArray params = JSONArray.parseArray(bodyParam); |
| | | |
| | | if (params == null || params.size() < 1) { |
| | | return; |
| | | } |
| | | |
| | | JSONObject param = null; |
| | | for(int paramIndex = 0 ;paramIndex < params.size() ; paramIndex ++){ |
| | | doWorkHeartbeat(chargeMachineDto,params.getJSONObject(paramIndex)); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 工作心跳 |
| | | * @param chargeMachineDto |
| | | * @param param |
| | | */ |
| | | private void doWorkHeartbeat(ChargeMachineDto chargeMachineDto, JSONObject param) { |
| | | |
| | | ChargeMachineOrderPo chargeMachineOrderPo = new ChargeMachineOrderPo(); |
| | | chargeMachineOrderPo.setOrderId(param.getString("chargeId")); |
| | | |
| | | chargeMachineOrderPo.setCommunityId(chargeMachineDto.getCommunityId()); |
| | | chargeMachineOrderPo.setEnergy(param.getString("energy")); |
| | | |
| | | chargeMachineOrderV1InnerServiceSMOImpl.updateChargeMachineOrder(chargeMachineOrderPo); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void workHeartbeat(ChargeMachineDto chargeMachineDto, String bodyParam) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<NotifyChargePortDto> getChargeHeartBeatParam(NotifyChargeOrderDto notifyChargeOrderDto) { |
| | | return null; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResponseEntity<String> heartbeat(@RequestBody NotifyChargeOrderDto notifyChargeOrderDto) { |
| | | return chargeCoreImpl.heartbeat(notifyChargeOrderDto); |
| | | public ResultVo workHeartbeat(@RequestBody NotifyChargeOrderDto notifyChargeOrderDto) { |
| | | return chargeCoreImpl.workHeartbeat(notifyChargeOrderDto); |
| | | } |
| | | |
| | | |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Base64; |
| | | |
| | | /** |
| | | * http://demo.homecommunity.cn/app/equipments/{id}/{port}/finish |
| | | * <p> |
| | | * 需要给叮叮厂家提供 |
| | | * http://demo.homecommunity.cn/app |
| | | * 注意demo.homecommunity.cn 改成自己的域名 |
| | | * 叮叮充电桩 结束充电回调处理类 |
| | | */ |
| | | @RestController |
| | | @RequestMapping(path = "/app/equipments") |
| | | public class NotifyDingDingChargeController extends BaseController { |
| | |
| | | private INotifyChargeV1InnerServiceSMO notifyChargeV1InnerServiceSMOImpl; |
| | | |
| | | /** |
| | | * <p>支付回调Api</p> |
| | | * <p>充电结束通知</p> |
| | | * |
| | | * @param request |
| | | * @throws Exception |
| | |
| | | * @param request |
| | | * @throws Exception |
| | | */ |
| | | @RequestMapping(path = "/{id}/event", method = RequestMethod.POST) |
| | | public ResponseEntity<String> heartbeat( |
| | | @RequestMapping(path = "/{id}/power", method = RequestMethod.POST) |
| | | public ResponseEntity<String> workHeartbeat( |
| | | @PathVariable String id, |
| | | @RequestBody String postInfo, |
| | | HttpServletRequest request) { |
| | | if (!validateSign(request, "/equipments/" + id + "/event", postInfo)) { |
| | | if (!validateSign(request, "/equipments/" + id + "/power", postInfo)) { |
| | | return new ResponseEntity<>("{\n" + |
| | | "\"code\" : -1,\n" + |
| | | "\"msg\" : \"鉴权失败\"\n" + |
| | | "}", HttpStatus.OK); |
| | | } |
| | | |
| | | JSONObject param = JSONObject.parseObject(postInfo); |
| | | NotifyChargeOrderDto notifyChargeOrderDto = new NotifyChargeOrderDto(); |
| | | notifyChargeOrderDto.setMachineCode(id); |
| | | notifyChargeOrderDto.setBodyParam(postInfo); |
| | | ResultVo resultVo = null; |
| | | resultVo = notifyChargeV1InnerServiceSMOImpl.workHeartbeat(notifyChargeOrderDto); |
| | | if (resultVo.getCode() == ResultVo.CODE_OK) { |
| | | resultVo.setCode(200); |
| | | resultVo.setMsg("success"); |
| | | } |
| | | |
| | | return notifyChargeV1InnerServiceSMOImpl.heartbeat(notifyChargeOrderDto); |
| | | |
| | | return ResultVo.createResponseEntity(resultVo); |
| | | } |
| | | |
| | | private boolean validateSign(HttpServletRequest request, String url, String postInfo) { |