zrj
2024-11-09 166d2ad42c652c938b754cf2407770c752322b95
应急空间统计修改,风险源统计修改
4 files modified
112 ■■■■■ changed files
src/main/java/org/springblade/common/utils/ShapeFileUtil.java 96 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/mapper/EmergencySpaceMapper.xml 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/mapper/RescueTeamMapper.xml 11 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/service/impl/RescueTeamServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/common/utils/ShapeFileUtil.java
@@ -135,6 +135,102 @@
    }
    /**
     * 导出shp文件
     *
     * @param map 属性列表{属性名:属性值}
     * @param fileName           导出shp文件名
     * @param geomType           geometry类型
     * @param saveFolder         导出位置
     */
    public static void exportShp(Map<String, Object> map,
                                 String fileName,
                                 String geomType,
                                 String saveFolder) {
        String path = saveFolder + "/" + fileName;
        //创建保存shp文件夹
        File dir = new File(path);
        if (!dir.exists()) {
            FileUtil.mkdir(dir);
        }
        //shp文件路径
        String shpFileName = fileName + ".shp";
        String fileUrl = path+ "/" + shpFileName;
        File file = new File(fileUrl);
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer = null;
        ShapefileDataStore ds = null;
        try {
            Map<String, Serializable> params = new HashMap<>();
            params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
            ds = (ShapefileDataStore) new ShapefileDataStoreFactory().createNewDataStore(params);
            //定义图形信息和属性信息
            SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
            //设置坐标系
            CoordinateReferenceSystem crs84 = CRS.decode("EPSG:4326", true);
            tb.setCRS(crs84);
            //设置文件名
            tb.setName(fileName);
            //定义导出shp文件地块属性名称
            String geomProperty = "the_geom";
            String idProperty = "ID";
            String nameProperty = "name";
            //设置图形类型
            if ("Polygon".equals(geomType)) {
                tb.add(geomProperty, Polygon.class);
            } else if ("MultiPolygon".equals(geomType)) {
                tb.add(geomProperty, MultiPolygon.class);
            } else if ("Point".equals(geomType)) {
                tb.add(geomProperty, Point.class);
            } else if ("MultiPoint".equals(geomType)) {
                tb.add(geomProperty, MultiPoint.class);
            } else if ("LineString".equals(geomType)) {
                tb.add(geomProperty, LineString.class);
            } else if ("MultiLineString".equals(geomType)) {
                tb.add(geomProperty, MultiLineString.class);
            } else {
                throw new ServiceException("Geometry中没有该类型:" + geomType);
            }
            //设置对应属性类型
            tb.add(idProperty, String.class);
            tb.add(nameProperty, String.class);
            //设置默认geometry
            tb.setDefaultGeometry(geomProperty);
            //创建
            ds.createSchema(tb.buildFeatureType());
            ds.setCharset(StandardCharsets.UTF_8);
            //设置Writer
            writer = ds.getFeatureWriter(ds.getTypeNames()[0],
                Transaction.AUTO_COMMIT);
            SimpleFeature feature;
            feature = writer.next();
            //属性赋值  geometry要赋值wkt格式的
            feature.setAttribute(geomProperty, new WKTReader().read((MapUtil.getStr(map, "geometry"))));
            feature.setAttribute(idProperty, MapUtil.getStr(map, idProperty));
            feature.setAttribute(nameProperty, MapUtil.getStr(map, nameProperty));
            writer.write();
        } catch (IOException | FactoryException | ParseException e) {
            e.printStackTrace();
        } finally {
            //关闭相关流
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (ds != null) {
                ds.dispose();
            }
        }
    }
    /**
     * 将文件解压
     * @param zipFile
     * @return
src/main/java/org/springblade/modules/yw/mapper/EmergencySpaceMapper.xml
@@ -40,7 +40,6 @@
        WHERE
            is_deleted = 0
            AND type IS NOT NULL
            AND firm_id IS NOT NULL
            GROUP BY type
    </select>
src/main/java/org/springblade/modules/yw/mapper/RescueTeamMapper.xml
@@ -41,13 +41,16 @@
    <!--自定义分页查询-->
    <select id="getStatisticData" resultType="java.util.Map">
        SELECT
            case when type=1 then '园区'
            when type =2 then '企业'
            end as type,
            team_name as type,
            count(*) AS num
        FROM
            yw_rescue_team
        GROUP BY type
        <where>
            <if test="rescueTeam.type!=null">
                and type = #{rescueTeam.type}
            </if>
        </where>
        GROUP BY team_name
    </select>
</mapper>
src/main/java/org/springblade/modules/yw/service/impl/RescueTeamServiceImpl.java
@@ -119,6 +119,10 @@
     */
    @Override
    public List<Map<String, Object>> getStatisticData(RescueTeamVO rescueTeam) {
        if (null==rescueTeam.getType()){
            // 设置默认为园区
            rescueTeam.setType(1);
        }
        // 查询并返回救援队伍统计
        return baseMapper.getStatisticData(rescueTeam);
    }