فهرست منبع

AC设备接口

zhj 2 سال پیش
والد
کامیت
3f6a408c2a

+ 2 - 0
src/main/java/com/welampiot/common/InterfaceResultEnum.java

@@ -144,6 +144,8 @@ public enum InterfaceResultEnum {
     BROADCAST_ADDRESS_UNIQUE_ERROR("0337","音柱地址已存在","The sound post address already exists","Адрес колонны уже существует"),
     CABLE_ADDRESS_UNIQUE_ERROR("0338","电缆地址已存在","The cable address already exists","Адрес кабеля уже существует"),
     CABLE_NAME_UNIQUE_ERROR("0339","电缆名称已存在","The cable name already exists","Имя кабеля уже существует"),
+    AC_ADDRESS_UNIQUE_ERROR("0340","AC设备地址已存在","The AC device address already exists","Адрес оборудования AC уже существует"),
+    AC_NAME_UNIQUE_ERROR("0341","AC设备名称已存在","The AC device name already exists","Название оборудования AC уже существует"),
     ;
     private String code;
     private String msgCn;

+ 188 - 0
src/main/java/com/welampiot/controller/AcDeviceController.java

@@ -0,0 +1,188 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dto.AcDevInfoDTO;
+import com.welampiot.service.AcDevInfoService;
+import com.welampiot.utils.ExcelUtil;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.AcDevInfoVO;
+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;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * ClassName: AcDeviceController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 14:53
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/acDevice")
+public class AcDeviceController {
+    @Autowired
+    private ToolUtils toolUtils;
+    @Autowired
+    private AcDevInfoService acDevInfoService;
+
+    /**
+     * 获取AC的列表
+     * @param request sectionList,page,count,keyword
+     * @return 获取AC的列表
+     */
+    @RequestMapping(value = "/acGetList", method = RequestMethod.POST)
+    public BaseResult<?> acGetList(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
+        Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
+        Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
+        Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
+        Integer download = (Integer) toolUtils.getRequestContent(request,"download",1);
+        String keyword = (String) toolUtils.getRequestContent(request,"keyword",2);
+        if (page == 0) page = 1;
+        if (count == 0) count = 16;
+        AcDevInfoVO acDevInfoVO = new AcDevInfoVO();
+        acDevInfoVO.setAreaId(areaId);
+        acDevInfoVO.setSectionId(sectionId);
+        acDevInfoVO.setVersion(version);
+        if (download == 0) {
+            acDevInfoVO.setPage(count * (page - 1));
+            acDevInfoVO.setCount(count);
+        }
+        acDevInfoVO.setKeyword(keyword);
+        acDevInfoVO.setSectionList(toolUtils.getSectionList(request));
+        List<AcDevInfoDTO> acDevList = acDevInfoService.getAcDevListByVO(acDevInfoVO);
+        AcDevInfoVO vo = new AcDevInfoVO();
+        vo.setList(acDevList);
+        if (download == 0) {
+            Integer acDevTotal = acDevInfoService.getAcDevTotal(acDevInfoVO);
+            double total = Math.ceil((double) acDevTotal / count);
+            vo.setTotal((int) total);
+        }
+        if (download == 1) {
+            String title;
+            if (version == 0) {
+                title = "编号,ac设备地址,ac设备名称,ip,行政区,路段,创建时间";
+            } else if (version == 1) {
+                title = "Number,Ac Device Address,Ac Device Name,IP,District,Road Section,Creation Time";
+            } else {
+                title = "Номер,адрес оборудования ac,название оборудования ac," +
+                        "ip,административный район,участок дороги,время создания";
+            }
+            List<String> titleList = Arrays.asList(title.split(","));
+            List<List<String>> contentList = new ArrayList<>();
+            for (AcDevInfoDTO a : acDevList) {
+                List<String> newString = new ArrayList<>();
+                newString.add(0, String.valueOf(acDevList.indexOf(a) + 1));
+                newString.add(1,a.getAcAddress());
+                newString.add(2,a.getDeviceName());
+                newString.add(3,a.getNetworkIP());
+                newString.add(4,a.getArea());
+                newString.add(5,a.getSection());
+                newString.add(6,a.getCreateTime());
+                contentList.add(acDevList.indexOf(a),newString);
+            }
+            String path = ExcelUtil.outExcel(titleList, contentList);
+            vo.setPath(path);
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
+    }
+
+    /**
+     * 删除AC设备
+     * @param request 设备id
+     * @return 删除AC设备
+     */
+    @RequestMapping(value = "/acDel", method = RequestMethod.POST)
+    public BaseResult<?> acDel(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        String id = (String) toolUtils.getRequestContent(request,"id",2);
+        if (id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        List<String> strings = Arrays.asList(id.split(","));
+        acDevInfoService.deleteAcDevData(strings);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
+
+    /**
+     * 添加编辑AC设备
+     * @param request 设备属性
+     * @return 添加编辑AC设备
+     */
+    @RequestMapping(value = "/acAdd", method = RequestMethod.POST)
+    public BaseResult<?> acAdd(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
+        Integer type = (Integer) toolUtils.getRequestContent(request,"type",1);
+        Integer areaId = (Integer) toolUtils.getRequestContent(request,"areaId",1);
+        Integer sectionId = (Integer) toolUtils.getRequestContent(request,"sectionId",1);
+        String deviceName = (String) toolUtils.getRequestContent(request,"deviceName",2);
+        String acAddress = (String) toolUtils.getRequestContent(request,"acAddress",2);
+        String networkIP = (String) toolUtils.getRequestContent(request,"networkIP",2);
+        String longitude = (String) toolUtils.getRequestContent(request,"longitude",2);
+        String latitude = (String) toolUtils.getRequestContent(request,"latitude",2);
+        if (areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,version);
+        if (sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,version);
+        if (deviceName.length() == 0 || acAddress.length() == 0)
+            return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
+        if (type == 0) {
+            if (networkIP.length() == 0)
+                return toolUtils.response(InterfaceResultEnum.LACK_NEED_PARAM,version);
+        }
+        if (latitude.length() == 0) latitude = "0";
+        if (longitude.length() == 0) longitude = "0";
+        AcDevInfoDTO acDevInfoDTO = new AcDevInfoDTO();
+        acDevInfoDTO.setType(type);
+        acDevInfoDTO.setAcAddress(acAddress);
+        acDevInfoDTO.setDeviceName(deviceName);
+        acDevInfoDTO.setAreaId(areaId);
+        acDevInfoDTO.setSectionId(sectionId);
+        acDevInfoDTO.setNetworkIP(networkIP);
+        acDevInfoDTO.setLongitude(Double.valueOf(longitude));
+        acDevInfoDTO.setLatitude(Double.valueOf(latitude));
+        long l = System.currentTimeMillis();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String format = simpleDateFormat.format(l);
+        if (id == 0) { // 添加
+            acDevInfoDTO.setCreateTime(format);
+            acDevInfoDTO.setUpdateTime(format);
+            AcDevInfoDTO dto = new AcDevInfoDTO();
+            dto.setSectionId(sectionId);
+            dto.setDeviceName(deviceName);
+            if (acDevInfoService.checkAcDevData(dto) > 0)
+                return toolUtils.response(InterfaceResultEnum.AC_NAME_UNIQUE_ERROR,version);
+            dto = new AcDevInfoDTO();
+            dto.setAcAddress(acAddress);
+            if (acDevInfoService.checkAcDevData(dto) > 0)
+                return toolUtils.response(InterfaceResultEnum.AC_ADDRESS_UNIQUE_ERROR,version);
+            acDevInfoService.addAcDevData(acDevInfoDTO);
+        } else { // 编辑
+            acDevInfoDTO.setId(id);
+            acDevInfoDTO.setUpdateTime(format);
+            AcDevInfoDTO dto = new AcDevInfoDTO();
+            dto.setId(id);
+            dto.setSectionId(sectionId);
+            dto.setDeviceName(deviceName);
+            if (acDevInfoService.checkAcDevData(dto) > 0)
+                return toolUtils.response(InterfaceResultEnum.AC_NAME_UNIQUE_ERROR,version);
+            dto = new AcDevInfoDTO();
+            dto.setId(id);
+            dto.setAcAddress(acAddress);
+            if (acDevInfoService.checkAcDevData(dto) > 0)
+                return toolUtils.response(InterfaceResultEnum.AC_ADDRESS_UNIQUE_ERROR,version);
+            acDevInfoService.updateAcDevData(acDevInfoDTO);
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
+}

+ 30 - 0
src/main/java/com/welampiot/dao/AcDevInfoDao.java

@@ -0,0 +1,30 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.AcDevInfoDTO;
+import com.welampiot.vo.AcDevInfoVO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ClassName: AcDevInfoDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 14:45
+ * @Version: v1.0
+ */
+public interface AcDevInfoDao {
+    List<AcDevInfoDTO> getAcDevListByVO(AcDevInfoVO vo);
+
+    Integer getAcDevTotal(AcDevInfoVO vo);
+
+    void deleteAcDevData(@Param("ids") List<String> ids);
+
+    void addAcDevData(AcDevInfoDTO dto);
+
+    void updateAcDevData(AcDevInfoDTO dto);
+
+    Integer checkAcDevData(AcDevInfoDTO dto);
+}

+ 51 - 0
src/main/java/com/welampiot/dto/AcDevInfoDTO.java

@@ -0,0 +1,51 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * ClassName: AcDevInfoDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 14:26
+ * @Version: v1.0
+ */
+@Data
+public class AcDevInfoDTO implements Serializable {
+    private Integer id;
+
+    private String acAddress;
+
+    private Integer type;
+
+    private String networkIP;
+
+    private String deviceName;
+
+    private String accessToken;
+
+    private String refreshToken;
+
+    private Integer areaId;
+
+    private Integer sectionId;
+
+    private Double longitude;
+
+    private Double latitude;
+
+    private String createTime;
+
+    private String updateTime;
+
+    private Integer online;
+
+    private String section;
+
+    private String area;
+
+    private static final long serialVersionUID = 1L;
+}

+ 29 - 0
src/main/java/com/welampiot/service/AcDevInfoService.java

@@ -0,0 +1,29 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.AcDevInfoDTO;
+import com.welampiot.vo.AcDevInfoVO;
+
+import java.util.List;
+
+/**
+ * ClassName: AcDevInfoService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 14:47
+ * @Version: v1.0
+ */
+public interface AcDevInfoService {
+    List<AcDevInfoDTO> getAcDevListByVO(AcDevInfoVO vo);
+
+    Integer getAcDevTotal(AcDevInfoVO vo);
+
+    void deleteAcDevData(List<String> ids);
+
+    void addAcDevData(AcDevInfoDTO dto);
+
+    void updateAcDevData(AcDevInfoDTO dto);
+
+    Integer checkAcDevData(AcDevInfoDTO dto);
+}

+ 55 - 0
src/main/java/com/welampiot/service/impl/AcDevInfoServiceImpl.java

@@ -0,0 +1,55 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.AcDevInfoDao;
+import com.welampiot.dto.AcDevInfoDTO;
+import com.welampiot.service.AcDevInfoService;
+import com.welampiot.vo.AcDevInfoVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * ClassName: AcDevInfoServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 14:47
+ * @Version: v1.0
+ */
+@Service
+public class AcDevInfoServiceImpl implements AcDevInfoService {
+    @Autowired
+    private AcDevInfoDao acDevInfoDao;
+
+    @Override
+    public List<AcDevInfoDTO> getAcDevListByVO(AcDevInfoVO vo) {
+        return acDevInfoDao.getAcDevListByVO(vo);
+    }
+
+    @Override
+    public Integer getAcDevTotal(AcDevInfoVO vo) {
+        return acDevInfoDao.getAcDevTotal(vo);
+    }
+
+    @Override
+    public void deleteAcDevData(List<String> ids) {
+        acDevInfoDao.deleteAcDevData(ids);
+    }
+
+    @Override
+    public void addAcDevData(AcDevInfoDTO dto) {
+        acDevInfoDao.addAcDevData(dto);
+    }
+
+    @Override
+    public void updateAcDevData(AcDevInfoDTO dto) {
+        acDevInfoDao.updateAcDevData(dto);
+    }
+
+    @Override
+    public Integer checkAcDevData(AcDevInfoDTO dto) {
+        return acDevInfoDao.checkAcDevData(dto);
+    }
+}

+ 41 - 0
src/main/java/com/welampiot/vo/AcDevInfoVO.java

@@ -0,0 +1,41 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.AcDevInfoDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: AcDevInfoVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/3 - 14:37
+ * @Version: v1.0
+ */
+@Data
+public class AcDevInfoVO implements Serializable {
+    private Integer areaId;
+
+    private Integer sectionId;
+
+    private Integer page;
+
+    private Integer count;
+
+    private Integer version;
+
+    private String keyword;
+
+    private String path;
+
+    private List<Integer> sectionList;
+
+    private List<AcDevInfoDTO> list;
+
+    private Integer total;
+
+    private static final long serialVersionUID = 1L;
+}

+ 145 - 0
src/main/resources/mapper/AcDevInfoMapper.xml

@@ -0,0 +1,145 @@
+<?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.AcDevInfoDao">
+    
+    <select id="getAcDevListByVO" resultType="AcDevInfoDTO">
+        select
+            a.id,
+            a.acAddress,
+            a.deviceName,
+            a.type,
+            a.networkIP,
+            a.createtime as createTime,
+            s.name as section
+            <choose>
+                <when test="version == 0">
+                    ,gl.chinese_name as area
+                </when>
+                <when test="version == 1">
+                    ,gl.english_name as area
+                </when>
+                <otherwise>
+                    ,gl.ru_name as area
+                </otherwise>
+            </choose>
+        from ac_dev_info a
+        left join section s on a.sectionid = s.id
+        left join global_location gl on s.pid = gl.id
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and a.sectionid in
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="areaId != null and areaId != 0">
+            and a.areaid = #{areaId}
+        </if>
+        <if test="sectionId != null and sectionId != 0">
+            and a.sectionid = #{sectionId}
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and (a.deviceName like '%${keyword}%' or a.acAddress like '%${keyword}%')
+        </if>
+        order by a.updatetime desc
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <select id="getAcDevTotal" resultType="Integer">
+        select
+            count(*)
+        from ac_dev_info a
+        left join section s on a.sectionid = s.id
+        left join global_location gl on s.pid = gl.id
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and a.sectionid in
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="areaId != null and areaId != 0">
+            and a.areaid = #{areaId}
+        </if>
+        <if test="sectionId != null and sectionId != 0">
+            and a.sectionid = #{sectionId}
+        </if>
+    </select>
+
+    <delete id="deleteAcDevData">
+        delete
+        from ac_dev_info
+        where id in
+        <foreach collection="ids" item="item" open="(" separator="," close=")">
+            #{ids}
+        </foreach>
+    </delete>
+
+    <insert id="addAcDevData" parameterType="AcDevInfoDTO" useGeneratedKeys="true" keyProperty="id">
+        insert into ac_dev_info(deviceName,
+                                acAddress,
+                                type,
+                                <if test="networkIP != null and networkIP != ''">
+                                    networkIP,
+                                </if>
+                                areaid,
+                                sectionid,
+                                latitude,
+                                longitude,
+                                createtime,
+                                updatetime)
+        values (#{deviceName},
+                #{acAddress},
+                #{type},
+                <if test="networkIP != null and networkIP != ''">
+                    #{networkIP},
+                </if>
+                #{areaId},
+                #{sectionId},
+                #{latitude},
+                #{longitude},
+                #{createTime},
+                #{updateTime})
+    </insert>
+
+    <update id="updateAcDevData" parameterType="AcDevInfoDTO">
+        update
+            ac_dev_info a
+        set
+            a.deviceName = #{deviceName},
+            a.acAddress = #{acAddress},
+            a.type = #{type},
+            <if test="networkIP != null and networkIP != ''">
+                a.networkIP = #{networkIP},
+            </if>
+            a.areaid = #{areaId},
+            a.sectionid = #{sectionId},
+            a.longitude = #{longitude},
+            a.latitude = #{latitude},
+            a.updatetime = #{updateTime}
+        where
+            a.id = #{id}
+    </update>
+
+    <select id="checkAcDevData" resultType="Integer">
+        select
+            count(*)
+        from ac_dev_info a
+        where 1=1
+        <if test="sectionId != null and sectionId != 0">
+            and a.sectionid = #{sectionId}
+        </if>
+        <if test="deviceName != null and deviceName != ''">
+            and a.deviceName = #{deviceName}
+        </if>
+        <if test="acAddress != null and acAddress != ''">
+            and a.acAddress = #{acAddress}
+        </if>
+        <if test="id != null and id != ''">
+            and a.id != #{id}
+        </if>
+    </select>
+
+</mapper>