| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.param.C3mChargingChargeParam; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.domain.C3mCharging; |
| | | import com.sandu.ximon.dao.domain.C3mChargingCharge; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.mapper.C3mChargingChargeMapper; |
| | |
| | | * @param |
| | | * @return |
| | | */ |
| | | public boolean updateCharge(List<C3mChargingCharge> chargeEntities) { |
| | | public boolean updateCharge(List<C3mChargingCharge> chargeEntities) { //TODO |
| | | // 删除原本存在的费率 |
| | | c3mChargingChargeMapper.deleteCharge(chargeEntities.get(0).getC3Id()); |
| | | Integer c3Id = chargeEntities.get(0).getC3Id(); |
| | | |
| | | if (c3Id == null) { |
| | | throw new BusinessException("c3Id不能为空"); |
| | | } |
| | | c3mChargingChargeMapper.deleteCharge(c3Id); |
| | | Long timestamp = new Date().getTime(); |
| | | |
| | | C3ChargingService chargingService = SpringContextHolder.getBean(C3ChargingService.class); |
| | | C3mCharging byId = chargingService.getById(c3Id); |
| | | if (byId == null) { |
| | | throw new BusinessException("c3Id不存在"); |
| | | } |
| | | String s = chargingService.setRate(byId.getC3Mac(), chargeEntities); |
| | | if (!"操作成功".equals(s)) { |
| | | throw new BusinessException("设置失败,失败原因: " + s); |
| | | } |
| | | // 将费率添加至数据库 |
| | | for (C3mChargingCharge c3m : chargeEntities) { |
| | | c3m.setTimestamp(timestamp); |
| | |
| | | //其他费率时,获取默认费率 |
| | | charge = 8.8; |
| | | } |
| | | //计算花费 费率*电量 |
| | | BigDecimal chargeDecimal = new BigDecimal(charge); |
| | | |
| | | //charge转化为BigDecimal |
| | | //double直接使用 new BigDecimal()时会出现精度问题,所以需要使用BigDecimal.valueOf()方法 并设置精度为2位小数 |
| | | BigDecimal chargeDecimal = BigDecimal.valueOf(charge).setScale(2, BigDecimal.ROUND_HALF_UP); |
| | | |
| | | return chargeDecimal; |
| | | } |
| | | } |