소스 검색

充电桩接口

zhj 2 년 전
부모
커밋
e40d3f1e4b

+ 70 - 0
src/main/java/com/welampiot/controller/ChargeController.java

@@ -0,0 +1,70 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.dto.ChargeDTO;
+import com.welampiot.service.ChargeService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.ChargeVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * ClassName: ChargeController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/18 - 11:35
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/api/charge")
+public class ChargeController {
+    @Autowired
+    private ChargeService chargeService;
+
+    @Autowired
+    private ToolUtils toolUtils;
+
+    /**
+     * 获取充电桩信息列表
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/devList", method = RequestMethod.POST)
+    public BaseResult<ChargeDTO> devList(HttpServletRequest request){
+        int page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
+        int count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
+        String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
+
+        ChargeDTO dto = new ChargeDTO();
+        dto.setPage(count * (page - 1));
+        dto.setCount(count);
+        dto.setKeyword(keyword);
+        dto.setSectionList(toolUtils.getSectionList(request));
+
+        ChargeVO vo = chargeService.getDevListByChargeDTO(dto);
+        return BaseResult.success(vo);
+    }
+
+    /**
+     * 获取充电桩统计信息
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/data", method = RequestMethod.POST)
+    public BaseResult<ChargeDTO> data(HttpServletRequest request){
+        String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
+        ChargeDTO dto = new ChargeDTO();
+        dto.setKeyword(keyword);
+        dto.setSectionList(toolUtils.getSectionList(request));
+        ChargeVO vo = chargeService.getDataByChargeDTO(dto);
+        return BaseResult.success(vo);
+    }
+}

+ 32 - 0
src/main/java/com/welampiot/dao/ChargeDao.java

@@ -0,0 +1,32 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.ChargeDTO;
+
+import java.util.List;
+
+/**
+ * ClassName: ChargeDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/18 - 11:01
+ * @Version: v1.0
+ */
+public interface ChargeDao {
+    List<ChargeDTO> getDevListByChargeDTO(ChargeDTO dto);
+
+    Integer getTotalBySectionList(ChargeDTO dto);
+
+    Integer getOnlineTotalBySectionList(ChargeDTO dto);
+
+    Integer getAlarmTotalBySectionList(ChargeDTO dto);
+
+    Integer getChargeTotalBySectionList(ChargeDTO dto);
+
+    List<ChargeDTO> getChargeTimeBySectionList(ChargeDTO dto);
+
+    List<ChargeDTO> getChargeMoneyBySectionList(ChargeDTO dto);
+
+    List<ChargeDTO> getChargeEnergyBySectionList(ChargeDTO dto);
+}

+ 134 - 0
src/main/java/com/welampiot/dto/ChargeDTO.java

@@ -0,0 +1,134 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: ChargeDTO
+ * Package: com.welampiot.dto
+ * Description: 充电桩
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/18 - 10:17
+ * @Version: v1.0
+ */
+@Data
+public class ChargeDTO implements Serializable {
+    /** 主键 **/
+    private Integer id;
+
+    /** 型号(0 云之声,1 唐沅)**/
+    private Integer model;
+
+    /** 序列号 **/
+    private String num;
+
+    /** 功率 **/
+    private Integer power;
+
+    /** 充电模式(0 = 快充,1 = 慢充)**/
+    private Integer chargeModel;
+
+    /** 灯杆id **/
+    private Integer lampPoleId;
+
+    /** 电桩类型(1 直流,2 交流,3 交直流一体,4 无线,5 其他)**/
+    private Integer type;
+
+    /** 最大电压 **/
+    private Float macVoltage;
+
+    /** 工作电压 **/
+    private Float voltage;
+
+    /** 最大电流 **/
+    private Float macCurrent;
+
+    /** 工作电流 **/
+    private Float current;
+
+    /** 创建时间 **/
+    private String createTime;
+
+    /** 电桩编码 **/
+    private String connectorCode;
+
+    /** 终端编码 **/
+    private String stationCode;
+
+    /** 电费描述 **/
+    private String electricityFee;
+
+    /** 服务费描述 **/
+    private String serviceFee;
+
+    /** 累计充电次数 **/
+    private Integer connectorNum;
+
+    /** 累计充电量 **/
+    private Float equipmentElectricity;
+
+    /** 累计收入 **/
+    private Float free;
+
+    /** 累计充电时间 **/
+    private Integer duration;
+
+    /** 在线状态(0 待机,1 在线) **/
+    private Integer online;
+
+    /** 数据更新时间 **/
+    private String updateTime;
+
+    /** 充电状态(0 待机,1 充电中) **/
+    private Integer status;
+
+    /** 本次充电开始时间 **/
+    private String startTime;
+
+    /** 本次充电结束时间 **/
+    private String endTime;
+
+    /** 是否故障(0 正常,1 故障)**/
+    private Integer alarm;
+
+    /** 每小时能耗 **/
+    private Float hourEnergy;
+
+    /** 故障状态(0 正常,1 故障)**/
+    private Integer alarmStatus;
+
+    /** 故障信息内容 **/
+    private String alarmInfo;
+
+    /** 本次充电费用 **/
+    private Float billAmt;
+
+    /** 本次充电量 **/
+    private Float energy;
+
+    /** IP地址 **/
+    private String ipAddr;
+
+    /** 安装时间 **/
+    private String installDate;
+
+    /** 过期时间 **/
+    private String expirationDate;
+
+    private Integer timezone;
+
+    private Integer total;
+
+    private Integer page;
+
+    private Integer count;
+
+    private String keyword;
+
+    private List<Integer> sectionList;
+
+    private static final long serialVersionUID = 1L;
+}

+ 19 - 0
src/main/java/com/welampiot/service/ChargeService.java

@@ -0,0 +1,19 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.ChargeDTO;
+import com.welampiot.vo.ChargeVO;
+
+/**
+ * ClassName: ChargeService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/18 - 11:13
+ * @Version: v1.0
+ */
+public interface ChargeService {
+    ChargeVO getDevListByChargeDTO(ChargeDTO dto);
+
+    ChargeVO getDataByChargeDTO(ChargeDTO dto);
+}

+ 134 - 0
src/main/java/com/welampiot/service/impl/ChargeServiceImpl.java

@@ -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;
+    }
+}

+ 2 - 0
src/main/java/com/welampiot/service/impl/ManholeServiceImpl.java

@@ -171,6 +171,7 @@ public class ManholeServiceImpl implements ManholeService {
                         }
                         manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
                     }
+                    manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
                     list.add(manholeDTO);
                 }
             });
@@ -217,6 +218,7 @@ public class ManholeServiceImpl implements ManholeService {
             }else {
                 manholeDTO.setStatus(0);
             }
+            manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
             list.add(manholeDTO);
         });
         vo.setList(list);

+ 38 - 0
src/main/java/com/welampiot/vo/ChargeVO.java

@@ -0,0 +1,38 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.ChargeDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: ChargeVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/18 - 11:14
+ * @Version: v1.0
+ */
+@Data
+public class ChargeVO implements Serializable {
+
+    private Integer total; //设备总数
+
+    private Integer onlineCount; //在线数
+
+    private Integer alarmCount; //告警数
+
+    private Integer chargeCount; //充电中数量
+
+    private Integer totalTime; //充电时长
+
+    private Float totalMoney; //充电总金额
+
+    private Float totalEng; //充电总能耗
+
+    private List<ChargeDTO> list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 137 - 0
src/main/resources/mapper/ChargeMapper.xml

@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.welampiot.dao.ChargeDao">
+
+    <select id="getDevListByChargeDTO" resultType="ChargeDTO">
+        select c.id,c.num,c.online,c.status,c.updateTime,c.starttime as startTime,c.endtime as endTime,
+               c.equipmentElectricity,c.free,c.connectorNum,c.hourEnergy,c.alarmStatus,c.alarmInfo,
+               c.install_date installDate,c.expiration_date expirationDate,s.timezone
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+            left join section s on lp.sectionid = s.id
+        where c.lamp_pole_id != 0
+            <if test="sectionList != null and !sectionList.isEmpty()">
+                and lp.sectionid in
+                <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                    #{dto}
+                </foreach>
+            </if>
+            <if test="keyword != null and keyword != ''">
+                and c.num like '%${keyword}%'
+            </if>
+        order by convert(lp.number using gbk) asc,c.id desc
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <select id="getTotalBySectionList" resultType="Integer">
+        select count(c.id) as total
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where 1=1 <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+    <!-- 在线数 -->
+    <select id="getOnlineTotalBySectionList" resultType="Integer">
+        select count(c.id) as total
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where c.online = 1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+    <!-- 告警数 -->
+    <select id="getAlarmTotalBySectionList" resultType="Integer">
+        select count(c.id) as total
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where c.online = 1 and c.alarmStatus = 1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+    <!-- 充电中的数量 -->
+    <select id="getChargeTotalBySectionList" resultType="Integer">
+        select count(c.id) as total
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where c.online = 1 and c.status = 1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+    <!-- 充电时长 -->
+    <select id="getChargeTimeBySectionList" resultType="ChargeDTO">
+        select c.id,c.duration
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+    <!-- 充电金额 -->
+    <select id="getChargeMoneyBySectionList" resultType="ChargeDTO">
+        select c.id,c.free
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+    <!-- 充电能耗 -->
+    <select id="getChargeEnergyBySectionList" resultType="ChargeDTO">
+        select c.id,c.equipmentElectricity
+        from charge c left join lamp_pole lp on lp.id = c.lamp_pole_id
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and c.num like '%${keyword}%'
+        </if>
+    </select>
+
+</mapper>

+ 2 - 2
src/main/resources/mapper/ManholeMapper.xml

@@ -58,7 +58,7 @@
     <select id="getListByDTO" resultType="com.welampiot.dto.ManholeDTO" parameterType="com.welampiot.dto.ManholeDTO">
         select m.id,m.name,m.areaid as areaId,m.sectionid as sectionId,m.model,m.address,
                m.online,m.angle,m.longitude,m.latitude,m.batteryVol,m.alarmStatus,m.alarmInfo,
-               m.updateTime,m.createTime,m.status,m.install_date installDate,count(m.id) as total,
+               m.updateTime,m.createTime,m.status,m.install_date installDate,
                m.expiration_date expirationDate,g.chinese_name chArea,g.english_name enArea,g.ru_name ruArea,
                p.chinese_name chCity,p.english_name enCity,p.ru_name ruCity,s.timezone,s.name as section
         from manhole m left join section s on m.sectionid = s.id
@@ -81,7 +81,7 @@
     
     <select id="getHistoryListByDTO" resultType="ManholeDTO">
         select m.angle,m.batteryVol,m.alarmStatus,m.alarmInfo,
-               m.updateTime,m.status,count(m.id) as total,s.timezone
+               m.updateTime,m.status,s.timezone
         from manhole m left join section s on m.sectionid = s.id
         where m.id = #{id}
         <if test="sectionList != null and !sectionList.isEmpty()">