| | |
| | | package com.java110.common.charge; |
| | | |
| | | import com.java110.common.smartMeter.ISmartMeterFactoryAdapt; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.account.AccountDto; |
| | | import com.java110.dto.chargeMachine.ChargeMachineDto; |
| | | import com.java110.dto.chargeMachineFactory.ChargeMachineFactoryDto; |
| | | import com.java110.dto.chargeMachineOrder.ChargeMachineOrderDto; |
| | | import com.java110.dto.chargeMachineOrder.NotifyChargeOrderDto; |
| | | import com.java110.dto.chargeMachineOrder.NotifyChargePortDto; |
| | | import com.java110.dto.chargeMachineOrderAcct.ChargeMachineOrderAcctDto; |
| | | import com.java110.dto.chargeMachinePort.ChargeMachinePortDto; |
| | | import com.java110.intf.common.IChargeMachineFactoryV1InnerServiceSMO; |
| | | import com.java110.intf.common.IChargeMachineOrderV1InnerServiceSMO; |
| | | import com.java110.intf.common.IChargeMachinePortV1InnerServiceSMO; |
| | | import com.java110.intf.common.IChargeMachineV1InnerServiceSMO; |
| | | import com.java110.intf.acct.IAccountInnerServiceSMO; |
| | | import com.java110.intf.common.*; |
| | | import com.java110.po.accountDetail.AccountDetailPo; |
| | | import com.java110.po.chargeMachineOrder.ChargeMachineOrderPo; |
| | | import com.java110.po.chargeMachineOrderAcct.ChargeMachineOrderAcctPo; |
| | | import com.java110.po.chargeMachinePort.ChargeMachinePortPo; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.factory.ApplicationContextFactory; |
| | |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class ChargeCoreImpl implements IChargeCore { |
| | | |
| | | @Autowired |
| | | private IAccountInnerServiceSMO accountInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IChargeMachineFactoryV1InnerServiceSMO chargeMachineFactoryV1InnerServiceSMOImpl; |
| | |
| | | |
| | | @Autowired |
| | | private IChargeMachinePortV1InnerServiceSMO chargeMachinePortV1InnerServiceSMOImpl; |
| | | |
| | | |
| | | @Autowired |
| | | private IChargeMachineOrderAcctV1InnerServiceSMO chargeMachineOrderAcctV1InnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public ResultVo startCharge(ChargeMachineDto chargeMachineDto, ChargeMachinePortDto chargeMachinePortDto, String chargeType, double duration, String orderId) { |
| | |
| | | List<NotifyChargePortDto> portDtos = chargeFactoryAdapt.getChargeHeartBeatParam(notifyChargeOrderDto); |
| | | |
| | | for (NotifyChargePortDto notifyChargePortDto : portDtos) { |
| | | doDealChargePort(notifyChargePortDto, notifyChargeOrderDto, chargeMachineDtos.get(0)); |
| | | doDealChargePort(notifyChargePortDto, notifyChargeOrderDto, chargeMachineDtos.get(0), chargeFactoryAdapt); |
| | | } |
| | | |
| | | return new ResponseEntity<>("{\n" + |
| | |
| | | * @param notifyChargePortDto |
| | | * @param notifyChargeOrderDto |
| | | */ |
| | | private void doDealChargePort(NotifyChargePortDto notifyChargePortDto, NotifyChargeOrderDto notifyChargeOrderDto, ChargeMachineDto chargeMachineDto) { |
| | | private void doDealChargePort(NotifyChargePortDto notifyChargePortDto, |
| | | NotifyChargeOrderDto notifyChargeOrderDto, |
| | | ChargeMachineDto chargeMachineDto, |
| | | IChargeFactoryAdapt chargeFactoryAdapt) { |
| | | |
| | | String preEnergy = "0"; |
| | | ChargeMachineOrderDto chargeMachineOrderDto = new ChargeMachineOrderDto(); |
| | | chargeMachineOrderDto.setOrderId(notifyChargePortDto.getOrderId()); |
| | | List<ChargeMachineOrderDto> orderDtos = chargeMachineOrderV1InnerServiceSMOImpl.queryChargeMachineOrders(chargeMachineOrderDto); |
| | | |
| | | Assert.listOnlyOne(orderDtos, "订单不存在"); |
| | | String state = ChargeMachineOrderDto.STATE_DOING; |
| | | if (preEnergy.equals(notifyChargePortDto.getEnergy())) { |
| | | state = ChargeMachineOrderDto.STATE_FINISH; |
| | | } |
| | | updateOrderState(notifyChargePortDto, state); |
| | | |
| | | //todo 主动调用关闭 |
| | | if (preEnergy.equals(notifyChargePortDto.getEnergy())) { |
| | | customStopCharge(notifyChargePortDto, chargeMachineDto, chargeFactoryAdapt, orderDtos); |
| | | } |
| | | |
| | | // todo 1.0 查询上报时间是否已经 扣款,如果扣款过,那么更新 充电电量 后返回 |
| | | |
| | | String powerTime = DateUtil.getFormatTimeString(notifyChargePortDto.getPowerTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | |
| | | ChargeMachineOrderAcctDto chargeMachineOrderAcctDto = new ChargeMachineOrderAcctDto(); |
| | | chargeMachineOrderAcctDto.setOrderId(notifyChargeOrderDto.getOrderId()); |
| | | chargeMachineOrderAcctDto.setPowerTime(powerTime); |
| | | List<ChargeMachineOrderAcctDto> chargeMachineOrderAcctDtos = chargeMachineOrderAcctV1InnerServiceSMOImpl.queryChargeMachineOrderAccts(chargeMachineOrderAcctDto); |
| | | |
| | | if (chargeMachineOrderAcctDtos != null && chargeMachineOrderAcctDtos.size() > 0) { |
| | | return; |
| | | } |
| | | |
| | | // todo 2.0 检查账户是否余额充足,如果余额不足,则 调用停止充电 将充电订单 修改成充电完成,并且修改备注 |
| | | |
| | | double price = Double.parseDouble(chargeMachineDto.getDurationPrice()); |
| | | |
| | | AccountDto accountDto = new AccountDto(); |
| | | accountDto.setAcctId(orderDtos.get(0).getAcctDetailId()); |
| | | accountDto.setAcctType(AccountDto.ACCT_TYPE_CASH); |
| | | List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto); |
| | | |
| | | if (accountDtos == null || accountDtos.size() < 1) { |
| | | throw new CmdException("请先充值,账户金额不足"); |
| | | } |
| | | |
| | | //todo 账户金额不足,无法支付小时费用,停止充电 |
| | | if (Double.parseDouble(accountDtos.get(0).getAmount()) < price) { |
| | | customStopCharge(notifyChargePortDto, chargeMachineDto, chargeFactoryAdapt, orderDtos); |
| | | updateOrderState(notifyChargePortDto, ChargeMachineOrderDto.STATE_FINISH); |
| | | return; |
| | | } |
| | | |
| | | |
| | | // todo 3.0 账户扣款 |
| | | AccountDetailPo accountDetailPo = new AccountDetailPo(); |
| | | accountDetailPo.setAcctId(accountDtos.get(0).getAcctId()); |
| | | accountDetailPo.setObjId(accountDtos.get(0).getObjId()); |
| | | accountDetailPo.setObjType(accountDtos.get(0).getObjType()); |
| | | accountDetailPo.setAmount(price + ""); |
| | | accountDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId)); |
| | | accountInnerServiceSMOImpl.withholdAccount(accountDetailPo); |
| | | |
| | | ChargeMachineOrderAcctPo chargeMachineOrderAcctPo = new ChargeMachineOrderAcctPo(); |
| | | chargeMachineOrderAcctPo.setAcctDetailId(accountDetailPo.getDetailId()); |
| | | chargeMachineOrderAcctPo.setAmount(price + ""); |
| | | chargeMachineOrderAcctPo.setCmoaId(GenerateCodeFactory.getGeneratorId("11")); |
| | | chargeMachineOrderAcctPo.setOrderId(notifyChargePortDto.getOrderId()); |
| | | chargeMachineOrderAcctPo.setAcctId(accountDtos.get(0).getAcctId()); |
| | | chargeMachineOrderAcctPo.setStartTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A)); |
| | | chargeMachineOrderAcctPo.setEndTime(DateUtil.getAddHoursStringA(DateUtil.getCurrentDate(), 1)); |
| | | chargeMachineOrderAcctPo.setRemark("一小时定时扣款"); |
| | | chargeMachineOrderAcctPo.setCommunityId(orderDtos.get(0).getCommunityId()); |
| | | chargeMachineOrderAcctPo.setEnergy(notifyChargePortDto.getEnergy()); |
| | | |
| | | chargeMachineOrderAcctV1InnerServiceSMOImpl.saveChargeMachineOrderAcct(chargeMachineOrderAcctPo); |
| | | |
| | | } |
| | | |
| | | private void updateOrderState(NotifyChargePortDto notifyChargePortDto, String state) { |
| | | ChargeMachineOrderPo chargeMachineOrderPo = new ChargeMachineOrderPo(); |
| | | chargeMachineOrderPo.setOrderId(notifyChargePortDto.getOrderId()); |
| | | chargeMachineOrderPo.setEnergy(notifyChargePortDto.getEnergy()); |
| | | chargeMachineOrderPo.setState(state); |
| | | |
| | | chargeMachineOrderV1InnerServiceSMOImpl.updateChargeMachineOrder(chargeMachineOrderPo); |
| | | } |
| | | |
| | | private void customStopCharge(NotifyChargePortDto notifyChargePortDto, ChargeMachineDto chargeMachineDto, IChargeFactoryAdapt chargeFactoryAdapt, List<ChargeMachineOrderDto> orderDtos) { |
| | | ChargeMachinePortDto chargeMachinePortDto = new ChargeMachinePortDto(); |
| | | chargeMachinePortDto.setMachineId(orderDtos.get(0).getMachineId()); |
| | | chargeMachinePortDto.setPortCode(notifyChargePortDto.getPortCode()); |
| | | List<ChargeMachinePortDto> chargeMachinePortDtos = chargeMachinePortV1InnerServiceSMOImpl.queryChargeMachinePorts(chargeMachinePortDto); |
| | | if (chargeMachinePortDtos != null && chargeMachinePortDtos.size() > 0) { |
| | | chargeFactoryAdapt.stopCharge(chargeMachineDto, chargeMachinePortDtos.get(0)); |
| | | } |
| | | } |
| | | } |