| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | 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.dao.domain.C3mChargingCharge; |
| | | import com.sandu.ximon.dao.domain.PoleBinding; |
| | | import com.sandu.ximon.dao.mapper.C3mChargingChargeMapper; |
| | | import com.sandu.ximon.dao.mapper.C3mChargingMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author liuhaonan |
| | | * @Date 2022/3/10 13:58 |
| | | * @Version 1.0 |
| | | * c3å
çµæ¡©è´¹çç¸å
³ |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class C3mChargingChargeService extends BaseServiceImpl<C3mChargingChargeMapper, C3mChargingCharge> { |
| | | private final C3mChargingChargeMapper c3mChargingChargeMapper; |
| | | private final PoleBindingService bindingService; |
| | | private final C3mChargingMapper chargingMapper; |
| | | |
| | | /** |
| | | * ä¿®æ¹è´¹ç |
| | | * |
| | | * @param chargeEntities |
| | | * @param |
| | | * @return |
| | | */ |
| | | public boolean updateCharge(List<C3mChargingCharge> chargeEntities) { |
| | | // å é¤åæ¬åå¨çè´¹ç |
| | | c3mChargingChargeMapper.deleteCharge(chargeEntities.get(0).getC3Id()); |
| | | Long timestamp = new Date().getTime(); |
| | | // å°è´¹çæ·»å è³æ°æ®åº |
| | | for (C3mChargingCharge c3m : chargeEntities) { |
| | | c3m.setTimestamp(timestamp); |
| | | save(c3m); |
| | | } |
| | | // LogService.getBean().log(userId,username,"ä¿®æ¹C3mè´¹ç",null, |
| | | // "{ "+ JSON.toJSONString(chargeEntities)+" }"); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æå
¥è´¹ç |
| | | * |
| | | * @param c3 |
| | | * @return |
| | | */ |
| | | public boolean initCharge(C3mChargingChargeParam c3) { |
| | | C3mChargingCharge charge = new C3mChargingCharge(); |
| | | BeanUtil.copyProperties(c3, charge); |
| | | charge.setTimestamp(new Date().getTime()); |
| | | // c3mChargingChargeMapper.insertCharge(charge); |
| | | return save(charge); |
| | | } |
| | | |
| | | /** |
| | | * èªå¨æå
¥é»è®¤è´¹ç |
| | | * |
| | | * @param c3Id |
| | | */ |
| | | public void initCharge(Integer c3Id) { |
| | | List<C3mChargingCharge> chargeList = getChargeByC3Id(c3Id); |
| | | if (chargeList.size() == 0) { |
| | | // ä¸åå¨è´¹çæ¶ï¼çæå个费çå¹¶æå
¥æ°æ®åº |
| | | C3mChargingCharge c3mChargeEntity = new C3mChargingCharge();/*C3mChargingCharge.getInitInstance(c3Id);*/ |
| | | c3mChargeEntity.setC3Id(c3Id); |
| | | c3mChargeEntity.setHour(0); |
| | | c3mChargeEntity.setMin(0); |
| | | c3mChargeEntity.setCharge(8.8); |
| | | c3mChargeEntity.setTimestamp(new Date().getTime()); |
| | | c3mChargingChargeMapper.insertCharge(c3mChargeEntity); |
| | | } |
| | | } |
| | | |
| | | |
| | | public List<C3mChargingCharge> getChargeByC3Id(Integer c3Id) { |
| | | // æ¥æ¾æ°æ®åºææè´¹ç |
| | | List<C3mChargingCharge> list = c3mChargingChargeMapper.getChargeByC3Id(c3Id); |
| | | // 夿listä¸ºåæ¡ç´æ¥è¿å |
| | | if (list.size() < 2) { |
| | | return list; |
| | | } |
| | | // å°æ¶åè¿è¡æåº |
| | | Collections.sort(list, new Comparator<C3mChargingCharge>() { |
| | | @Override |
| | | public int compare(C3mChargingCharge o1, C3mChargingCharge o2) { |
| | | int i = o2.getHour().compareTo(o1.getHour()); |
| | | if (i == 0) { |
| | | return o2.getMin().compareTo(o1.getMin()); |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object obj) { |
| | | return false; |
| | | } |
| | | }); |
| | | // list翻转 |
| | | Collections.reverse(list); |
| | | // æ¶é´æ®µåç¬¦æ¼æ¥ |
| | | for (int i = 1; i < list.size(); i++) { |
| | | C3mChargingCharge pre = list.get(i - 1); |
| | | C3mChargingCharge now = list.get(i); |
| | | pre.setStrTime( |
| | | pre.getHour() + "ç¹" + pre.getMin() + "å å° " + |
| | | now.getHour() + "ç¹" + now.getMin() + "å" |
| | | ); |
| | | if (i == list.size() - 1) { |
| | | pre = now; |
| | | now = list.get(0); |
| | | if (now.getHour() < pre.getHour()) { |
| | | pre.setStrTime( |
| | | pre.getHour() + "ç¹" + pre.getMin() + "å å° " + |
| | | "鿥" + now.getHour() + "ç¹" + now.getMin() + "å" |
| | | ); |
| | | } else { |
| | | pre.setStrTime( |
| | | pre.getHour() + "ç¹" + pre.getMin() + "å å° " + |
| | | now.getHour() + "ç¹" + now.getMin() + "å" |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®ç¯æidæ¥æ¾è´¹ç |
| | | * |
| | | * @param poleId |
| | | * @return |
| | | */ |
| | | public List<C3mChargingCharge> getChargeByPoleId(Long poleId) { |
| | | PoleBinding one = bindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceType, 2).eq(PoleBinding::getPoleId, poleId)); |
| | | if (one == null) { |
| | | throw new BusinessException("æªæ¾å°ç»å®å
³ç³»"); |
| | | } |
| | | Long c3Id = chargingMapper.getAllByC3Mac(one.getDeviceCode()).getC3Id(); |
| | | return getChargeByC3Id(c3Id.intValue()); |
| | | } |
| | | |
| | | public boolean deleteC3mCharging(Integer c3mId) { |
| | | return c3mChargingChargeMapper.deleteCharge(c3mId); |
| | | } |
| | | } |