cloudroam
2025-01-09 eeb3b46afe7da500bce62daad35ded0886df3b88
Merge branch 'master-v4' of http://47.96.225.205:8888/r/flowerbackend-v2 into master-v4
已修改5个文件
已添加2个文件
318 ■■■■■ 文件已修改
src/main/java/com/mzl/flower/dto/response/system/AreaAppDTO.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/system/AreaAppTmpDTO.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/district/DistrictTengxunService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/district/DistrictTengxunServiceImpl.java 221 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/map/MapTengxunServiceImpl.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/system/ProvinceController.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/statisticsAnalysis/FlowerMaterialMapper.xml 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/system/AreaAppDTO.java
对比新文件
@@ -0,0 +1,22 @@
package com.mzl.flower.dto.response.system;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AreaAppDTO {
    private String value;
    private String text;
    private List<AreaAppDTO> children=new ArrayList<>();
    public AreaAppDTO(String value, String text) {
        this.value = value;
        this.text = text;
    }
}
src/main/java/com/mzl/flower/dto/response/system/AreaAppTmpDTO.java
对比新文件
@@ -0,0 +1,27 @@
package com.mzl.flower.dto.response.system;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Data
@NoArgsConstructor
public class AreaAppTmpDTO {
    private String areaId;
    private String areaType;
    private String name;
    private String parentAreaId;
    private List<AreaAppTmpDTO> children=new ArrayList<>();
    public AreaAppTmpDTO(String areaId, String areaType, String name, String parentAreaId) {
        this.areaId = areaId;
        this.areaType = areaType;
        this.name = name;
        this.parentAreaId = parentAreaId;
    }
}
src/main/java/com/mzl/flower/service/district/DistrictTengxunService.java
@@ -68,4 +68,8 @@
    String getChineseArea();
    void clearChineseDataCache();
    String getChineseAreaForApp();
    String getChineseAreaForWeb();
}
src/main/java/com/mzl/flower/service/impl/district/DistrictTengxunServiceImpl.java
@@ -4,11 +4,15 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mzl.flower.base.cache.StringCacheClient;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.dto.map.tengxun.TengxunDistrict;
import com.mzl.flower.dto.request.district.CreateDistrictTengxunDTO;
import com.mzl.flower.dto.response.district.DistrictTengxunVO;
import com.mzl.flower.dto.response.system.AreaAppDTO;
import com.mzl.flower.dto.response.system.AreaAppTmpDTO;
import com.mzl.flower.dto.response.system.AreaDTO;
import com.mzl.flower.entity.district.DistrictTengxunDO;
import com.mzl.flower.entity.district.DistrictTengxunDO;
@@ -49,6 +53,9 @@
    @Autowired
    private StringCacheClient stringCacheClient;
    @Autowired
    private Gson gson;
    @Override
    public void refreshDistrict() {
        List<DistrictTengxunDO> districtTengxunDOList = getAllDistrict();
@@ -104,7 +111,7 @@
        }
        // 映射当前节点
        AreaDTO targetNode = new AreaDTO(sourceNode.getName(), sourceNode.getName());
        AreaDTO targetNode = new AreaDTO(sourceNode.getCode(), sourceNode.getName());
        // 递归映射子节点
        if (sourceNode.getChildren() != null) {
@@ -116,6 +123,60 @@
        return targetNode;
    }
    public static AreaDTO transformCodeEqName(DistrictTengxunVO sourceNode) {
        if (sourceNode == null) {
            return null;
        }
        // 映射当前节点
        AreaDTO targetNode = new AreaDTO(sourceNode.getName(), sourceNode.getName());
        // 递归映射子节点
        if (sourceNode.getChildren() != null) {
            for (DistrictTengxunVO child : sourceNode.getChildren()) {
                targetNode.getChildren().add(transformCodeEqName(child));
            }
        }
        return targetNode;
    }
    public static AreaAppTmpDTO transformApp(DistrictTengxunVO sourceNode,int level) {
        if (sourceNode == null) {
            return null;
        }
        // 映射当前节点
        AreaAppTmpDTO targetNode = new AreaAppTmpDTO(sourceNode.getId(), level+"", sourceNode.getName(), sourceNode.getParentId());
        // 递归映射子节点
        if (sourceNode.getChildren() != null) {
            for (DistrictTengxunVO child : sourceNode.getChildren()) {
                targetNode.getChildren().add(transformApp(child,level++));
            }
        }
        return targetNode;
    }
    public static AreaAppDTO transformApp2(DistrictTengxunVO sourceNode) {
        if (sourceNode == null) {
            return null;
        }
        // 映射当前节点
        AreaAppDTO targetNode = new AreaAppDTO(sourceNode.getCode(), sourceNode.getName());
        // 递归映射子节点
        if (sourceNode.getChildren() != null) {
            for (DistrictTengxunVO child : sourceNode.getChildren()) {
                targetNode.getChildren().add(transformApp2(child));
            }
        }
        return targetNode;
    }
    @Override
    public List<DistrictTengxunDO> getAllDistrict() {
@@ -362,6 +423,164 @@
    @Override
    public void clearChineseDataCache() {
        stringCacheClient.delete("CHINA_AREA_DATA");
        stringCacheClient.delete("CHINA_AREA_DATA_APP");
        stringCacheClient.delete("CHINA_AREA_DATA_WEB");
    }
    @Override
    public String getChineseAreaForApp() {
        String result = stringCacheClient.get("CHINA_AREA_DATA_APP");
        if (StringUtils.isNotBlank(result)) {
            return result;
        } else {
            // 打印每个根节点对应的树形 JSON
            Gson gson = new Gson();
            List<DistrictTengxunDO> districtTengxunDOList = getAllDistrict();
            List<DistrictTengxunVO> districtTengxunVOList = ConverterUtil.transList(districtTengxunDOList, DistrictTengxunVO.class);
            if (CollectionUtils.isNotEmpty(districtTengxunDOList)) {
                // 找出所有 parent_id 为 null 的节点作为根节点集合
                List<DistrictTengxunVO> roots = districtTengxunVOList.stream()
                        .filter(districtTengxunVO -> districtTengxunVO.getParentId() == null)
                        .collect(Collectors.toList());
                // 遍历根节点,构建每棵树形结构
                List<AreaAppTmpDTO> areaDTOList = new ArrayList<>();
                for (DistrictTengxunVO rootNode : roots) {
                    // 构建树形结构
                    buildTree(rootNode, districtTengxunVOList);
                    // 将树形转换成前端需要的结构
                    AreaAppTmpDTO areaDTO = transformApp(rootNode,1);
                    areaDTOList.add(areaDTO);
                }
                result=gson.toJson(areaDTOList);
                if(StringUtils.isNotBlank(result)){
                    stringCacheClient.set("CHINA_AREA_DATA_APP", result);
                }
                return result;
            }
            return "";
        }
    }
    @Override
    public String getChineseAreaForWeb() {
        String result = stringCacheClient.get("CHINA_AREA_DATA_WEB");
        if (StringUtils.isNotBlank(result)) {
            return result;
        } else {
            // 打印每个根节点对应的树形 JSON
            Gson gson = new Gson();
            List<DistrictTengxunDO> districtTengxunDOList = getAllDistrict();
            List<DistrictTengxunVO> districtTengxunVOList = ConverterUtil.transList(districtTengxunDOList, DistrictTengxunVO.class);
            if (CollectionUtils.isNotEmpty(districtTengxunDOList)) {
                // 找出所有 parent_id 为 null 的节点作为根节点集合
                List<DistrictTengxunVO> roots = districtTengxunVOList.stream()
                        .filter(districtTengxunVO -> districtTengxunVO.getParentId() == null)
                        .collect(Collectors.toList());
                // 遍历根节点,构建每棵树形结构
                List<AreaDTO> areaDTOList = new ArrayList<>();
                for (DistrictTengxunVO rootNode : roots) {
                    // 构建树形结构
                    buildTree(rootNode, districtTengxunVOList);
                    // 将树形转换成前端需要的结构
                    AreaDTO areaDTO = transformCodeEqName(rootNode);
                    areaDTOList.add(areaDTO);
                }
                List<AreaDTO> formatterDistrict =normalizeTreeToThreeLevels(areaDTOList);
//                result=gson.toJson(areaDTOList);
                result=gson.toJson(formatterDistrict);
                if(StringUtils.isNotBlank(result)){
                    stringCacheClient.set("CHINA_AREA_DATA_WEB", result);
                }
                return result;
            }
            return "";
        }
    }
    public static List<AreaDTO> normalizeTreeToThreeLevels(List<AreaDTO> tree) {
        List<AreaDTO> result = new ArrayList<>();
        for (AreaDTO node : tree) {
            int depth = getTreeDepth(node);
            if(depth<3){
                List<AreaDTO> childrenList=new ArrayList<>();
                childrenList.add(node);
                AreaDTO tengxunDistrict= new AreaDTO();
                BeanUtils.copyProperties(node, tengxunDistrict);
                tengxunDistrict.setChildren(childrenList);
                // 虚拟的id、code
                tengxunDistrict.setCode(tengxunDistrict.getCode());
                result.add(tengxunDistrict);
                continue;
            }else{
                result.add(node);
            }
        }
        return result;
    }
    private static int getTreeDepth(AreaDTO node) {
        if (node == null || node.getChildren() == null || node.getChildren().isEmpty()) {
            return 1;
        }
        int maxDepth = 0;
        for (AreaDTO child : node.getChildren()) {
            maxDepth = Math.max(maxDepth, getTreeDepth(child));
        }
        return maxDepth + 1;
    }
    public String getChineseAreaForApp2() {
        String result = stringCacheClient.get("CHINA_AREA_DATA_APP");
        if (StringUtils.isNotBlank(result)) {
            return result;
        } else {
            // 打印每个根节点对应的树形 JSON
            Gson gson = new Gson();
            List<DistrictTengxunDO> districtTengxunDOList = getAllDistrict();
            List<DistrictTengxunVO> districtTengxunVOList = ConverterUtil.transList(districtTengxunDOList, DistrictTengxunVO.class);
            if (CollectionUtils.isNotEmpty(districtTengxunDOList)) {
                // 找出所有 parent_id 为 null 的节点作为根节点集合
                List<DistrictTengxunVO> roots = districtTengxunVOList.stream()
                        .filter(districtTengxunVO -> districtTengxunVO.getParentId() == null)
                        .collect(Collectors.toList());
                // 遍历根节点,构建每棵树形结构
                List<AreaAppDTO> areaDTOList = new ArrayList<>();
                for (DistrictTengxunVO rootNode : roots) {
                    // 构建树形结构
                    buildTree(rootNode, districtTengxunVOList);
                    // 将树形转换成前端需要的结构
                    AreaAppDTO areaDTO = transformApp2(rootNode);
                    areaDTOList.add(areaDTO);
                }
                result=gson.toJson(areaDTOList);
                if(StringUtils.isNotBlank(result)){
                    stringCacheClient.set("CHINA_AREA_DATA_APP", result);
                }
                return result;
            }
            return "";
        }
    }
}
src/main/java/com/mzl/flower/service/impl/map/MapTengxunServiceImpl.java
@@ -51,13 +51,22 @@
            List<TengxunDistrict> allDistricts = response.getResult();
            // 将腾讯地图返回的数据格式转换成标准的三层结构
            List<TengxunDistrict> formatterDistrict =normalizeTreeToThreeLevels(allDistricts);
//            List<TengxunDistrict> formatterDistrict =normalizeTreeToThreeLevels(allDistricts);
//
//            List<TengxunDistrict> allTengxunDistricts = new ArrayList<>();
//            // 递归遍历所有的节点,然后把所有节点加入到 allDistricts 列表中
//            for (TengxunDistrict tengxunDistrict : formatterDistrict){
//                addDistrictToList(tengxunDistrict, null, allTengxunDistricts);  // 从根节点开始,父节点 ID 为 null
//            }
//            List<TengxunDistrict> formatterDistrict =normalizeTreeToThreeLevels(allDistricts);
            List<TengxunDistrict> allTengxunDistricts = new ArrayList<>();
            // 递归遍历所有的节点,然后把所有节点加入到 allDistricts 列表中
            for (TengxunDistrict tengxunDistrict : formatterDistrict){
            for (TengxunDistrict tengxunDistrict : allDistricts){
                addDistrictToList(tengxunDistrict, null, allTengxunDistricts);  // 从根节点开始,父节点 ID 为 null
            }
            List<DistrictTengxunDO> districtTengxunDOList= ConverterUtil.transList(allTengxunDistricts, DistrictTengxunDO.class);
            districtTengxunService.saveRemoteDistricts(districtTengxunDOList);
src/main/java/com/mzl/flower/web/system/ProvinceController.java
@@ -88,4 +88,16 @@
        districtTengxunService.clearChineseDataCache();
        return returnData(R.SUCCESS.getCode(), null);
    }
    @ApiOperation(value = "获取中国省市区数据")
    @GetMapping("/web/area/json")
    public ResponseEntity<String> getChineseAreaForWeb() {
        // 高德地图
//        return returnData(R.SUCCESS.getCode(), districtService.getChineseArea());
        // 腾讯地图
        return returnData(R.SUCCESS.getCode(), districtTengxunService.getChineseAreaForWeb());
//        return returnData(R.SUCCESS.getCode(), provinceService.getChineseArea());
    }
}
src/main/resources/mapper/statisticsAnalysis/FlowerMaterialMapper.xml
@@ -125,15 +125,18 @@
            ))
        </if>
        <if test="dto.flowerStatus != null and dto.flowerStatus != ''">
            <if test="dto.flowerStatus == 'OFF'">
                AND f.status IN ('OFF', 'FORCE_OFF')
            </if>
            <if test="dto.flowerStatus != 'OFF'">
                AND f.status = #{dto.flowerStatus}
            </if>
        </if>
<!--        <if test="dto.flowerStatus != null and dto.flowerStatus != ''">-->
<!--            <if test="dto.flowerStatus == 'OFF'">-->
<!--                AND f.status IN ('OFF', 'FORCE_OFF')-->
<!--            </if>-->
<!--            <if test="dto.flowerStatus != 'OFF'">-->
<!--                AND f.status = #{dto.flowerStatus}-->
<!--            </if>-->
<!--        </if>-->
        <if test="dto.flowerStatus != null and dto.flowerStatus != ''">
            AND f.status = #{dto.flowerStatus}
        </if>
        <if test="dto.flowerLevel !=null and dto.flowerLevel !=''">
            AND  f.`level` = #{dto.flowerLevel}
        </if>