| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrProject.network; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.aop.SsoAop; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voPr.VoNetwork; | 
|---|
|  |  |  | import com.dy.pipIrrProject.network.dto.Network; | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author ZhuBaoMin | 
|---|
|  |  |  | * @date 2024-08-27 17:08 | 
|---|
|  |  |  | * @LastEditTime 2024-08-27 17:08 | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path = "network") | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | public class NetworkCtrl { | 
|---|
|  |  |  | private final NetworkSv networkSv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加管网 | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@RequestBody @Valid Network po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String result = networkSv.addNetworks(po); | 
|---|
|  |  |  | if(result.trim().length()> 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //PrWaterNetwork prWaterNetwork = null; | 
|---|
|  |  |  | //Long networkId = null; | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //JSONArray networks = po.getData(); | 
|---|
|  |  |  | //for (int i = 0; i < networks.size(); i++) { | 
|---|
|  |  |  | //    // 取出一笔绘画 | 
|---|
|  |  |  | //    JSONObject polyline = networks.getJSONObject(i); | 
|---|
|  |  |  | //    // 添加该笔绘画 | 
|---|
|  |  |  | //    prWaterNetwork = new PrWaterNetwork(); | 
|---|
|  |  |  | //    prWaterNetwork.setNetworkType(po.getType()); | 
|---|
|  |  |  | //    networkId = networkSv.addNetwork(prWaterNetwork); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    // 取出一笔绘画中的坐标点 | 
|---|
|  |  |  | //    JSONArray coordinates = polyline.getJSONArray("coordinates"); | 
|---|
|  |  |  | //    for (int j = 0; j < coordinates.size(); j++) { | 
|---|
|  |  |  | //        JSONObject point = coordinates.getJSONObject(j); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        PrNetworkCoordinates prNetworkCoordinates = new PrNetworkCoordinates(); | 
|---|
|  |  |  | //        prNetworkCoordinates.setNetworkId(networkId); | 
|---|
|  |  |  | //        prNetworkCoordinates.setLat(point.getBigDecimal("lat")); | 
|---|
|  |  |  | //        prNetworkCoordinates.setLng(point.getBigDecimal("lng")); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        Long coordinateId = Optional.ofNullable(networkSv.addNetworkCoordinate(prNetworkCoordinates)).orElse(0L); | 
|---|
|  |  |  | //        if (coordinateId.equals(0)) { | 
|---|
|  |  |  | //            return BaseResponseUtils.buildErrorMsg(ProjectResultCode.SAVA_NETWORK_ERROR.getMessage()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取全部管网 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "/all") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<List<VoNetwork>> getNetworks() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(networkSv.getNetworks()); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取开卡记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|