|
@@ -0,0 +1,134 @@
|
|
|
+package com.welampiot.service.impl;
|
|
|
+
|
|
|
+import com.welampiot.dao.ChargeDao;
|
|
|
+import com.welampiot.dto.ChargeDTO;
|
|
|
+import com.welampiot.service.ChargeService;
|
|
|
+import com.welampiot.vo.ChargeVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ClassName: ChargeServiceImpl
|
|
|
+ * Package: com.welampiot.service.impl
|
|
|
+ * Description:
|
|
|
+ *
|
|
|
+ * @Author: zhj_Start
|
|
|
+ * @Create: 2023/4/18 - 11:16
|
|
|
+ * @Version: v1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ChargeServiceImpl implements ChargeService {
|
|
|
+ @Autowired
|
|
|
+ private ChargeDao chargeDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChargeVO getDevListByChargeDTO(ChargeDTO dto) {
|
|
|
+ ChargeVO vo = new ChargeVO();
|
|
|
+ List<ChargeDTO> devList = chargeDao.getDevListByChargeDTO(dto);
|
|
|
+ List<ChargeDTO> list = new ArrayList<>();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ devList.forEach(chargeDTO ->{
|
|
|
+ if (chargeDTO.getOnline() != null && chargeDTO.getOnline() == 1){
|
|
|
+ chargeDTO.setOnline(1);
|
|
|
+ }else {
|
|
|
+ chargeDTO.setOnline(0);
|
|
|
+ }
|
|
|
+ if (chargeDTO.getStatus() != null && chargeDTO.getStatus() == 1){
|
|
|
+ chargeDTO.setStatus(1);
|
|
|
+ }else {
|
|
|
+ chargeDTO.setAlarmStatus(0);
|
|
|
+ }
|
|
|
+ if (chargeDTO.getUpdateTime() != null && !chargeDTO.getUpdateTime().equals("")){
|
|
|
+ Date cmdTime;
|
|
|
+ try {
|
|
|
+ cmdTime = simpleDateFormat.parse(chargeDTO.getUpdateTime());
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //判断时区,为null默认东八区
|
|
|
+ long timezone = chargeDTO.getTimezone() == null ? 8 : chargeDTO.getTimezone();
|
|
|
+ long l = cmdTime.getTime() + timezone * 3600 * 1000;
|
|
|
+ cmdTime = new Date(l);
|
|
|
+ chargeDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
|
|
|
+ }else {
|
|
|
+ chargeDTO.setUpdateTime("");
|
|
|
+ }
|
|
|
+ if (chargeDTO.getStartTime() != null){
|
|
|
+ try {
|
|
|
+ chargeDTO.setStartTime(simpleDateFormat.format(simpleDateFormat.parse(chargeDTO.getStartTime())));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ chargeDTO.setStartTime("");
|
|
|
+ }
|
|
|
+ if (chargeDTO.getEndTime() != null){
|
|
|
+ try {
|
|
|
+ chargeDTO.setEndTime(simpleDateFormat.format(simpleDateFormat.parse(chargeDTO.getEndTime())));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ chargeDTO.setEndTime("");
|
|
|
+ }
|
|
|
+ if (chargeDTO.getAlarmStatus() != null && chargeDTO.getAlarmStatus() == 1){
|
|
|
+ chargeDTO.setAlarmStatus(1);
|
|
|
+ }else {
|
|
|
+ chargeDTO.setAlarmStatus(0);
|
|
|
+ }
|
|
|
+ if (chargeDTO.getAlarmInfo() == null){
|
|
|
+ chargeDTO.setAlarmInfo("");
|
|
|
+ }
|
|
|
+ if (chargeDTO.getInstallDate() != null){
|
|
|
+ try {
|
|
|
+ chargeDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(chargeDTO.getInstallDate())));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ chargeDTO.setInstallDate("");
|
|
|
+ }
|
|
|
+ if (chargeDTO.getExpirationDate() != null){
|
|
|
+ try {
|
|
|
+ chargeDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(chargeDTO.getExpirationDate())));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ chargeDTO.setExpirationDate("");
|
|
|
+ }
|
|
|
+ chargeDTO.setTotal(chargeDao.getTotalBySectionList(dto));
|
|
|
+ list.add(chargeDTO);
|
|
|
+ });
|
|
|
+ vo.setList(list);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChargeVO getDataByChargeDTO(ChargeDTO dto) {
|
|
|
+ ChargeVO vo = new ChargeVO();
|
|
|
+ vo.setTotal(chargeDao.getTotalBySectionList(dto));
|
|
|
+ vo.setOnlineCount(chargeDao.getOnlineTotalBySectionList(dto));
|
|
|
+ vo.setAlarmCount(chargeDao.getAlarmTotalBySectionList(dto));
|
|
|
+ vo.setChargeCount(chargeDao.getChargeTotalBySectionList(dto));
|
|
|
+ //充电总时长
|
|
|
+ List<ChargeDTO> chargeTime = chargeDao.getChargeTimeBySectionList(dto);
|
|
|
+ Integer sumTime = chargeTime.stream().mapToInt(chargeDTO -> Integer.parseInt(chargeDTO.getDuration().toString())).sum();
|
|
|
+ vo.setTotalTime(sumTime);
|
|
|
+ //充电总金额
|
|
|
+ List<ChargeDTO> chargeMoney = chargeDao.getChargeMoneyBySectionList(dto);
|
|
|
+ Double sumMoney = chargeMoney.stream().mapToDouble(chargeDTO -> Float.parseFloat(chargeDTO.getFree().toString())).sum();
|
|
|
+ vo.setTotalMoney(Float.parseFloat(String.format("%.2f", sumMoney)));
|
|
|
+ //充电总能耗
|
|
|
+ List<ChargeDTO> chargeEnergy = chargeDao.getChargeEnergyBySectionList(dto);
|
|
|
+ Double sumEnergy = chargeEnergy.stream().mapToDouble(chargeDTO -> Float.parseFloat(chargeDTO.getEquipmentElectricity().toString())).sum();
|
|
|
+ vo.setTotalEng(Float.parseFloat(String.format("%.2f", sumEnergy)));
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+}
|