| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.param.C3mChargingChargeParam; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.domain.C3mChargingCharge; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.mapper.C3mChargingChargeMapper; |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalTime; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | |
| | | c3m.setTimestamp(timestamp); |
| | | save(c3m); |
| | | } |
| | | // LogService.getBean().log(userId,username,"修改C3m费率",null, |
| | | // "{ "+ JSON.toJSONString(chargeEntities)+" }"); |
| | | |
| | | /** |
| | | * c3充电桩费率更改 日志记录开始 |
| | | */ |
| | | String content = "c3充电桩费率更改:" + JSON.toJSONString(chargeEntities); |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "c3充电桩费率更改", content); |
| | | /** |
| | | * c3充电桩费率更改 日志记录结束 |
| | | */ |
| | | return true; |
| | | } |
| | | |
| | |
| | | BeanUtil.copyProperties(c3, charge); |
| | | charge.setTimestamp(new Date().getTime()); |
| | | // c3mChargingChargeMapper.insertCharge(charge); |
| | | |
| | | |
| | | return save(charge); |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 根据灯杆id查找费率 |
| | | * |
| | | * @param poleId |
| | | * @return |
| | | */ |
| | |
| | | Long c3Id = chargingMapper.getAllByC3Mac(one.getDeviceCode()).getC3Id(); |
| | | return getChargeByC3Id(c3Id.intValue()); |
| | | } |
| | | |
| | | public boolean deleteC3mCharging(Integer c3mId) { |
| | | return c3mChargingChargeMapper.deleteCharge(c3mId); |
| | | } |
| | | |
| | | /** |
| | | * 根据c3Id查找费率 并计算花费 |
| | | * |
| | | * @param c3Id |
| | | * @return |
| | | */ |
| | | public BigDecimal getCostByC3id(Long c3Id, Integer power) { |
| | | List<C3mChargingCharge> list = list(Wrappers.lambdaQuery(C3mChargingCharge.class).eq(C3mChargingCharge::getC3Id, c3Id)); |
| | | //获取当前时间 |
| | | LocalTime localTime = LocalTime.now(); |
| | | //遍历费率集合 判断当前时间是否在费率时间段内 |
| | | LocalTime startTime; |
| | | LocalTime endTime; |
| | | //默认费率 |
| | | Double charge = 8.8; |
| | | if (list.size() > 1) { |
| | | //费率条数大于1时,遍历费率集合 获取当前时间段的费率 |
| | | for (int i = 0; i < list.size(); i++) { |
| | | //获取费率时间段 转化为LocalTime |
| | | startTime = LocalTime.of(list.get(i).getHour(), list.get(i).getMin()); |
| | | endTime = LocalTime.of(list.get(i + 1).getHour(), list.get(i + 1).getMin()); |
| | | if (i == list.size()) { |
| | | startTime = LocalTime.of(list.get(i).getHour(), list.get(i).getMin()); |
| | | endTime = LocalTime.of(list.get(0).getHour(), list.get(0).getMin()); |
| | | } |
| | | //判断当前时间是否在费率时间段内 |
| | | if (localTime.isAfter(startTime) && localTime.isBefore(endTime)) { |
| | | //获取费率 |
| | | charge = list.get(i).getCharge(); |
| | | } |
| | | |
| | | } |
| | | } else if (list.size() == 1) { |
| | | //只有一条费率时,直接获取费率 |
| | | charge = list.get(0).getCharge(); |
| | | } else { |
| | | //其他费率时,获取默认费率 |
| | | charge = 8.8; |
| | | } |
| | | //计算花费 费率*电量 |
| | | BigDecimal chargeDecimal = new BigDecimal(charge); |
| | | BigDecimal powerDecimal = new BigDecimal(power); |
| | | BigDecimal result = chargeDecimal.multiply(powerDecimal); |
| | | return result; |
| | | } |
| | | } |