Browse Source

获取回路历史数据总数;省份城市二级下拉;区域跟路段二级下拉;

zhj 10 months ago
parent
commit
0233bcfe18

+ 2 - 0
src/main/java/com/welampiot/controller/LoopController.java

@@ -500,7 +500,9 @@ public class LoopController {
         if (id == null || id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
         loopDataLogVO.setPageAndCount(loopDataLogVO.getPage(), loopDataLogVO.getCount());
         List<LoopDataLogDTO> loopDatalogList = loopDataLogService.getLoopDataLogListByLoopDataLogVO(loopDataLogVO);
+        Integer total = loopDataLogService.getLoopDataLogTotalById(id);
         LoopDataLogVO loopDataLogVO1 = new LoopDataLogVO();
+        loopDataLogVO1.setTotal(total);
         loopDataLogVO1.setList(loopDatalogList);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,loopDataLogVO1);
     }

+ 29 - 1
src/main/java/com/welampiot/controller/UserController.java

@@ -24,7 +24,7 @@ import java.util.stream.Stream;
 @CrossOrigin
 @RequestMapping("/user")
 //@Slf4j
-public class UserController {
+public class UserController extends BaseController {
     private final static Logger log = LoggerFactory.getLogger(UserController.class);
 
     @Autowired
@@ -1165,4 +1165,32 @@ public class UserController {
         globalLocationVO.setList(newProvinceList);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,globalLocationVO);
     }
+
+    /**
+     * 省份城市二级下拉
+     */
+    @RequestMapping(value = "/provinceCityNav", method = RequestMethod.POST)
+    public BaseResult<?> provinceCityNav(BaseVO baseVO) {
+        Integer version = baseVO.getVersion();
+        List<Integer> sectionList = getSectionList(baseVO.getUsername());
+        baseVO.setSectionList(sectionList);
+        List<GlobalLocationDTO> list = globalLocationService.getProvinceCityNavByBaseVO(baseVO);
+        GlobalLocationVO globalLocationVO = new GlobalLocationVO();
+        globalLocationVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, globalLocationVO);
+    }
+
+    /**
+     * 区域跟路段二级下拉
+     */
+    @RequestMapping(value = "/areaSectionNav", method = RequestMethod.POST)
+    public BaseResult<?> areaSectionNav(BaseVO baseVO) {
+        Integer version = baseVO.getVersion();
+        List<Integer> sectionList = getSectionList(baseVO.getUsername());
+        baseVO.setSectionList(sectionList);
+        List<GlobalLocationDTO> list = globalLocationService.getAreaSectionNavByBaseVO(baseVO);
+        GlobalLocationVO globalLocationVO = new GlobalLocationVO();
+        globalLocationVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, globalLocationVO);
+    }
 }

+ 3 - 0
src/main/java/com/welampiot/dao/GlobalLocationDao.java

@@ -2,6 +2,7 @@ package com.welampiot.dao;
 
 import com.welampiot.dto.GlobalLocationDTO;
 import com.welampiot.dto.SectionDTO;
+import com.welampiot.vo.BaseVO;
 import com.welampiot.vo.GlobalLocationVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -53,4 +54,6 @@ public interface GlobalLocationDao {
     List<GlobalLocationDTO> getAreaList(GlobalLocationDTO dto);
     GlobalLocationDTO getTimeZoneData(SectionDTO dto);
     GlobalLocationDTO getLocationBySectionId(@Param("sectionId") Integer sectionId);
+    List<GlobalLocationDTO> getProvinceCityNavByBaseVO(BaseVO baseVO);
+    List<GlobalLocationDTO> getAreaSectionNavByBaseVO(BaseVO baseVO);
 }

+ 2 - 0
src/main/java/com/welampiot/dao/LoopDataLogDao.java

@@ -2,9 +2,11 @@ package com.welampiot.dao;
 
 import com.welampiot.dto.LoopDataLogDTO;
 import com.welampiot.vo.LoopDataLogVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
 public interface LoopDataLogDao {
     List<LoopDataLogDTO> getLoopDataLogListByLoopDataLogVO(LoopDataLogVO loopDataLogVO);
+    Integer getLoopDataLogTotalById(@Param("id") Integer id);
 }

+ 5 - 0
src/main/java/com/welampiot/dto/GlobalLocationDTO.java

@@ -63,6 +63,11 @@ public class GlobalLocationDTO implements Serializable {
     private List<GlobalLocationDTO> provinceList;
     private List<GlobalLocationDTO> cityList;
     private List<GlobalLocationDTO> areaList;
+    private Integer cityId;
+    private String cityName;
+    private Integer sectionId;
+    private String sectionName;
+    private List<GlobalLocationDTO> subList;
 
     private Integer lampCount;
     private Integer lampPoleCount;

+ 3 - 0
src/main/java/com/welampiot/service/GlobalLocationService.java

@@ -2,6 +2,7 @@ package com.welampiot.service;
 
 import com.welampiot.dto.GlobalLocationDTO;
 import com.welampiot.dto.SectionDTO;
+import com.welampiot.vo.BaseVO;
 import com.welampiot.vo.GlobalLocationVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -38,4 +39,6 @@ public interface GlobalLocationService {
     List<GlobalLocationDTO> getAreaList(GlobalLocationDTO dto);
     GlobalLocationDTO getTimeZoneData(SectionDTO dto);
     GlobalLocationDTO getLocationBySectionId(Integer sectionId);
+    List<GlobalLocationDTO> getProvinceCityNavByBaseVO(BaseVO baseVO);
+    List<GlobalLocationDTO> getAreaSectionNavByBaseVO(BaseVO baseVO);
 }

+ 1 - 0
src/main/java/com/welampiot/service/LoopDataLogService.java

@@ -7,4 +7,5 @@ import java.util.List;
 
 public interface LoopDataLogService {
     List<LoopDataLogDTO> getLoopDataLogListByLoopDataLogVO(LoopDataLogVO loopDataLogVO);
+    Integer getLoopDataLogTotalById(Integer id);
 }

+ 55 - 3
src/main/java/com/welampiot/service/impl/GlobalLocationServiceImpl.java

@@ -4,14 +4,13 @@ import com.welampiot.dao.GlobalLocationDao;
 import com.welampiot.dto.GlobalLocationDTO;
 import com.welampiot.dto.SectionDTO;
 import com.welampiot.service.GlobalLocationService;
+import com.welampiot.vo.BaseVO;
 import com.welampiot.vo.GlobalLocationVO;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * ClassName: GlobalLocationServiceImpl
@@ -257,4 +256,57 @@ public class GlobalLocationServiceImpl implements GlobalLocationService {
     public GlobalLocationDTO getLocationBySectionId(Integer sectionId) {
         return globalLocationDao.getLocationBySectionId(sectionId);
     }
+
+    @Override
+    public List<GlobalLocationDTO> getProvinceCityNavByBaseVO(BaseVO baseVO) {
+        List<GlobalLocationDTO> provinceCityNav = globalLocationDao.getProvinceCityNavByBaseVO(baseVO);
+        // 使用 HashMap 存储省份
+        Map<Integer, GlobalLocationDTO> provinceMap = new HashMap<>();
+
+        for (GlobalLocationDTO item : provinceCityNav) {
+            // 获取或创建省份对象
+            GlobalLocationDTO province = getGlobalLocation(provinceMap, item);
+
+            // 创建城市对象并添加到省份的子列表中
+            GlobalLocationDTO city = new GlobalLocationDTO();
+            city.setId(item.getCityId());
+            city.setName(item.getCityName());
+            province.getSubList().add(city);
+        }
+
+        // 将 Map 转换为 List
+        return new ArrayList<>(provinceMap.values());
+    }
+
+    private GlobalLocationDTO getGlobalLocation(Map<Integer, GlobalLocationDTO> map,
+                                          GlobalLocationDTO item)
+    {
+        return map.computeIfAbsent(item.getId(), k -> {
+            GlobalLocationDTO p = new GlobalLocationDTO();
+            p.setId(item.getId());
+            p.setName(item.getName());
+            p.setSubList(new ArrayList<>());
+            return p;
+        });
+    }
+
+    @Override
+    public List<GlobalLocationDTO> getAreaSectionNavByBaseVO(BaseVO baseVO) {
+        List<GlobalLocationDTO> provinceCityNav = globalLocationDao.getAreaSectionNavByBaseVO(baseVO);
+        // 使用 HashMap 存储区域
+        Map<Integer, GlobalLocationDTO> areaMap = new HashMap<>();
+
+        for (GlobalLocationDTO item : provinceCityNav) {
+            // 获取或创建区域对象
+            GlobalLocationDTO area = getGlobalLocation(areaMap, item);
+            // 创建路段对象并添加到区域的子列表中
+            GlobalLocationDTO section = new GlobalLocationDTO();
+            section.setId(item.getSectionId());
+            section.setName(item.getSectionName());
+            area.getSubList().add(section);
+        }
+
+        // 将 Map 转换为 List
+        return new ArrayList<>(areaMap.values());
+    }
 }

+ 5 - 0
src/main/java/com/welampiot/service/impl/LoopDataLogServiceImpl.java

@@ -19,4 +19,9 @@ public class LoopDataLogServiceImpl implements LoopDataLogService {
     public List<LoopDataLogDTO> getLoopDataLogListByLoopDataLogVO(LoopDataLogVO loopDataLogVO) {
         return loopDataLogDao.getLoopDataLogListByLoopDataLogVO(loopDataLogVO);
     }
+
+    @Override
+    public Integer getLoopDataLogTotalById(Integer id) {
+        return loopDataLogDao.getLoopDataLogTotalById(id);
+    }
 }

+ 1 - 0
src/main/java/com/welampiot/vo/LoopDataLogVO.java

@@ -10,5 +10,6 @@ import java.util.List;
 @EqualsAndHashCode(callSuper = true)
 public class LoopDataLogVO extends BaseVO {
     private Integer id;
+    private Integer total;
     List<LoopDataLogDTO> list;
 }

+ 63 - 0
src/main/resources/mapper/GlobalLocationMapper.xml

@@ -404,4 +404,67 @@
     <select id="getLoction" resultType="GlobalLocationDTO">
         select longitude,latitude
     </select>
+    
+    <select id="getProvinceCityNavByBaseVO" resultType="GlobalLocationDTO">
+        SELECT a.id,b.id AS cityId
+            <choose>
+                <when test="version == 0">
+                    ,a.chinese_name AS `name`
+                </when>
+                <when test="version == 1">
+                    ,a.english_name AS `name`
+                </when>
+                <otherwise>
+                    ,a.ru_name AS `name`
+                </otherwise>
+            </choose>
+            <choose>
+                <when test="version == 0">
+                    ,b.chinese_name AS cityName
+                </when>
+                <when test="version == 1">
+                    ,b.english_name AS cityName
+                </when>
+                <otherwise>
+                    ,b.ru_name AS cityName
+                </otherwise>
+            </choose>
+        FROM section s
+        LEFT JOIN global_location c on c.id = s.pid
+        LEFT JOIN global_location b on b.id = c.pid
+        LEFT JOIN global_location a on a.id = b.pid
+        WHERE a.id IS NOT NULL
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            AND s.id IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY b.id
+    </select>
+
+    <select id="getAreaSectionNavByBaseVO" resultType="GlobalLocationDTO">
+        SELECT a.id,s.id AS sectionId,s.name AS sectionName
+        <choose>
+            <when test="version == 0">
+                ,a.chinese_name AS `name`
+            </when>
+            <when test="version == 1">
+                ,a.english_name AS `name`
+            </when>
+            <otherwise>
+                ,a.ru_name AS `name`
+            </otherwise>
+        </choose>
+        FROM section s
+        LEFT JOIN global_location a on a.id = s.pid
+        WHERE a.id IS NOT NULL
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            AND s.id IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+    
 </mapper>

+ 6 - 0
src/main/resources/mapper/LoopDataLogMapper.xml

@@ -14,4 +14,10 @@
         </if>
     </select>
 
+    <select id="getLoopDataLogTotalById" resultType="Integer">
+        select count(*)
+        from loop_data_log l
+        where l.loop_id = #{id}
+    </select>
+
 </mapper>