liurunyu
2024-10-29 1d33686e8f3e25b8db7d33ed162991f75ff1258d
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/block/BlockCtrl.java
@@ -94,15 +94,12 @@
     * 根据指定条件获取片区,2024-08-14新增,替换原来的片区分页查询
     *
     * @param qo
     * @param bindingResult
     * @param
     * @return
     */
    @GetMapping(path = "/some")
    @SsoAop()
    public BaseResponse<QueryResultVo<List<VoBlock>>> getBlocks(@Valid QueryVo qo, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
    public BaseResponse<QueryResultVo<List<VoBlock>>> getBlocks(QueryVo qo) {
        try {
            return BaseResponseUtils.buildSuccess(this.sv.getBlocks(qo));
        } catch (Exception e) {
@@ -171,42 +168,44 @@
        }
        JSONArray graphs = po.getGraphs();
        for (int i = 0; i < graphs.size(); i++) {
            JSONObject graph = graphs.getJSONObject(i);
        if(graphs != null && graphs.size() > 0){
            for (int i = 0; i < graphs.size(); i++) {
                JSONObject graph = graphs.getJSONObject(i);
            // 添加地图图形记录
            BaMapGraph baMapGraph = new BaMapGraph();
            baMapGraph.setBlockId(blockId);
            switch (graph.getString("type")) {
                case "CircleMarker":
                    baMapGraph.setGraphType(graphTypeENUM.CIRCLE_MARKER.getCode());
                    break;
                case "Polygon":
                    baMapGraph.setGraphType(graphTypeENUM.POLYGON.getCode());
                    break;
                case "Polyline":
                    baMapGraph.setGraphType(graphTypeENUM.POLYLINE.getCode());
                    break;
            }
            Long graphId = Optional.ofNullable(this.sv.addMapGraph(baMapGraph)).orElse(0L);
            if (graphId.equals(0)) {
                return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
            }
                // 添加地图图形记录
                BaMapGraph baMapGraph = new BaMapGraph();
                baMapGraph.setBlockId(blockId);
                switch (graph.getString("type")) {
                    case "CircleMarker":
                        baMapGraph.setGraphType(graphTypeENUM.CIRCLE_MARKER.getCode());
                        break;
                    case "Polygon":
                        baMapGraph.setGraphType(graphTypeENUM.POLYGON.getCode());
                        break;
                    case "Polyline":
                        baMapGraph.setGraphType(graphTypeENUM.POLYLINE.getCode());
                        break;
                }
                Long graphId = Optional.ofNullable(this.sv.addMapGraph(baMapGraph)).orElse(0L);
                if (graphId.equals(0)) {
                    return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
                }
            // 添加地图图形坐标记录
            JSONArray coordinates = graph.getJSONArray("coordinates");
            for (int j = 0; j < coordinates.size(); j++) {
                JSONArray coordinate = coordinates.getJSONArray(j);
                for (int k = 0; k < coordinate.size(); k++) {
                    JSONObject point = coordinate.getJSONObject(k);
                // 添加地图图形坐标记录
                JSONArray coordinates = graph.getJSONArray("coordinates");
                for (int j = 0; j < coordinates.size(); j++) {
                    JSONArray coordinate = coordinates.getJSONArray(j);
                    for (int k = 0; k < coordinate.size(); k++) {
                        JSONObject point = coordinate.getJSONObject(k);
                    BaMapCoordinates mapCoordinates = new BaMapCoordinates();
                    mapCoordinates.setGraphId(graphId);
                    mapCoordinates.setLat(point.getBigDecimal("lat"));
                    mapCoordinates.setLng(point.getBigDecimal("lng"));
                    Long coordinateId = Optional.ofNullable(this.sv.addMapCoordinate(mapCoordinates)).orElse(0L);
                    if (coordinateId.equals(0)) {
                        return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
                        BaMapCoordinates mapCoordinates = new BaMapCoordinates();
                        mapCoordinates.setGraphId(graphId);
                        mapCoordinates.setLat(point.getBigDecimal("lat"));
                        mapCoordinates.setLng(point.getBigDecimal("lng"));
                        Long coordinateId = Optional.ofNullable(this.sv.addMapCoordinate(mapCoordinates)).orElse(0L);
                        if (coordinateId.equals(0)) {
                            return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
                        }
                    }
                }
            }
@@ -266,6 +265,7 @@
     * @return
     */
    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> update(@RequestBody @Valid Block po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
@@ -298,14 +298,56 @@
            return BaseResponseUtils.buildFail("数据库存储失败");
        }
        // 删除片区关联的地图图形
        this.sv.deleteMapGraph(blockId);
        // 删除地图图形坐标
        this.sv.deleteMapCoordinates(blockId);
        // 删除片区关联的地图图形
        this.sv.deleteMapGraph(blockId);
        JSONArray graphs = po.getGraphs();
        if(graphs != null && graphs.size() > 0){
            for (int i = 0; i < graphs.size(); i++) {
                JSONObject graph = graphs.getJSONObject(i);
                // 添加地图图形记录
                BaMapGraph baMapGraph = new BaMapGraph();
                baMapGraph.setBlockId(blockId);
                switch (graph.getString("type")) {
                    case "CircleMarker":
                        baMapGraph.setGraphType(graphTypeENUM.CIRCLE_MARKER.getCode());
                        break;
                    case "Polygon":
                        baMapGraph.setGraphType(graphTypeENUM.POLYGON.getCode());
                        break;
                    case "Polyline":
                        baMapGraph.setGraphType(graphTypeENUM.POLYLINE.getCode());
                        break;
                }
                Long graphId = Optional.ofNullable(this.sv.addMapGraph(baMapGraph)).orElse(0L);
                if (graphId.equals(0)) {
                    return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
                }
                // 添加地图图形坐标记录
                JSONArray coordinates = graph.getJSONArray("coordinates");
                for (int j = 0; j < coordinates.size(); j++) {
                    JSONArray coordinate = coordinates.getJSONArray(j);
                    for (int k = 0; k < coordinate.size(); k++) {
                        JSONObject point = coordinate.getJSONObject(k);
                        BaMapCoordinates mapCoordinates = new BaMapCoordinates();
                        mapCoordinates.setGraphId(graphId);
                        mapCoordinates.setLat(point.getBigDecimal("lat"));
                        mapCoordinates.setLng(point.getBigDecimal("lng"));
                        Long coordinateId = Optional.ofNullable(this.sv.addMapCoordinate(mapCoordinates)).orElse(0L);
                        if (coordinateId.equals(0)) {
                            return BaseResponseUtils.buildErrorMsg(SystemResultCode.SAVA_BLOCK_ERROR.getMessage());
                        }
                    }
                }
            }
        }
        return BaseResponseUtils.buildSuccess(true);
    }
    /**
     * 删除片区
@@ -325,6 +367,7 @@
    //@GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE)
    @GetMapping(path = "delete")
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> delete(Long id) {
        if (id == null) {
@@ -341,11 +384,26 @@
            return BaseResponseUtils.buildFail("数据库存储失败");
        }
        // 删除片区关联的地图图形
        this.sv.deleteMapGraph(id);
        // 删除地图图形坐标
        this.sv.deleteMapCoordinates(id);
        // 删除片区关联的地图图形
        this.sv.deleteMapGraph(id);
        return BaseResponseUtils.buildSuccess(true);
    }
    /**
     * 获取片区、分水房联动视图,添加农户时使用
     * @return
     */
    @GetMapping(path = "/block_divides")
    @SsoAop()
    public BaseResponse<JSONArray> getBlockDivides() {
        try {
            return BaseResponseUtils.buildSuccess(this.sv.getBlockDivides());
        } catch (Exception e) {
            log.error("获取开卡记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    }
}