|  |  |  | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponse; | 
|---|
|  |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
|---|
|  |  |  | import com.dy.common.webUtil.ResultCodeMsg; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoPr.PrFlowMonitoring; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoPr.PrFlowmeter; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.pojoPr.PrMonitoringFlowmeter; | 
|---|
|  |  |  | import com.dy.pipIrrProject.result.ProjectResultCode; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.Optional; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author ZhuBaoMin | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "流量监测站、流量计关联管理", description = "流量监测站、流量计关联操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="moni_flow") | 
|---|
|  |  |  | @RequestMapping(path = "moni_flow") | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | public class MoniFlowCtrl { | 
|---|
|  |  |  | private final MoniFlowSv moniFlowSv; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 流量监测站绑定流量计 | 
|---|
|  |  |  | *      若流量监测站或流量计不存在需提示用户 | 
|---|
|  |  |  | *      若流量监测站已经与流量计绑定需提示用户 | 
|---|
|  |  |  | * @param po 绑定关系对象 | 
|---|
|  |  |  | * 若流量监测站或流量计不存在需提示用户 | 
|---|
|  |  |  | * 若流量监测站已经与流量计绑定需提示用户 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po            绑定关系对象 | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "bind", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> bind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | public BaseResponse<Boolean> bind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 根据编号分别获取流量监测站、流量计未删除记录数 | 
|---|
|  |  |  | Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoring(po.getMonitoringId())).orElse(0); | 
|---|
|  |  |  | Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeter(po.getFlowmeterId())).orElse(0); | 
|---|
|  |  |  | if(recFlowMonitoring == 0 || recFlowmeter == 0) { | 
|---|
|  |  |  | Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoringByFlowMonitoringId(po.getMonitoringId())).orElse(0); | 
|---|
|  |  |  | Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeterByCode(po.getFlowmeterId())).orElse(0); | 
|---|
|  |  |  | if (recFlowMonitoring == 0 || recFlowmeter == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.STATION_OR_FLOWMETER_NO_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 根据编号获取已绑定数量 | 
|---|
|  |  |  | Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte)1)).orElse(0); | 
|---|
|  |  |  | if(recordCount > 0) { | 
|---|
|  |  |  | Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte) 1)).orElse(0); | 
|---|
|  |  |  | if (recordCount > 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_HAS_BINDED_FLOWMETER.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrMonitoringFlowmeter prMonitoringFlowmeter = DtoToMoniFlowPojo.INSTANCT.po2vo(po); | 
|---|
|  |  |  | Date operateTime = new Date(); | 
|---|
|  |  |  | prMonitoringFlowmeter .setOperatedt(operateTime); | 
|---|
|  |  |  | prMonitoringFlowmeter.setOperatetype((byte)1); | 
|---|
|  |  |  | prMonitoringFlowmeter.setOperatedt(operateTime); | 
|---|
|  |  |  | prMonitoringFlowmeter.setOperatetype((byte) 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrFlowmeter flowmeter = new PrFlowmeter(); | 
|---|
|  |  |  | flowmeter.setMonitoringId(po.getMonitoringId().toString()); | 
|---|
|  |  |  | flowmeter.setId(po.getFlowmeterId()); | 
|---|
|  |  |  | flowmeter.setOperator(po.getOperator()); | 
|---|
|  |  |  | flowmeter.setOperateDt(operateTime); | 
|---|
|  |  |  | Integer shu = flowmeterSv.flowmeterAddMonId(flowmeter); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer rec = Optional.ofNullable(moniFlowSv.addRecord(prMonitoringFlowmeter)).orElse(0); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0 || shu == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "添加解绑记录", description = "添加解绑记录") | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "unbind", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> unbind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | public BaseResponse<Boolean> unbind(@RequestBody @Valid DtoMoniFlow po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 根据编号分别获取流量监测站、流量计未删除记录数 | 
|---|
|  |  |  | Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoring(po.getMonitoringId())).orElse(0); | 
|---|
|  |  |  | Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeter(po.getFlowmeterId())).orElse(0); | 
|---|
|  |  |  | if(recFlowMonitoring == 0 || recFlowmeter == 0) { | 
|---|
|  |  |  | Integer recFlowMonitoring = Optional.ofNullable(flowMonitoringSv.getRecordCountOfFlowMonitoringByFlowMonitoringId(po.getMonitoringId())).orElse(0); | 
|---|
|  |  |  | Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeterByCode(po.getFlowmeterId())).orElse(0); | 
|---|
|  |  |  | if (recFlowMonitoring == 0 || recFlowmeter == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.STATION_OR_FLOWMETER_NO_EXIST.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 根据编号获取已绑定数量 | 
|---|
|  |  |  | Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte)2)).orElse(0); | 
|---|
|  |  |  | if(recordCount > 0) { | 
|---|
|  |  |  | Integer recordCount = Optional.ofNullable(moniFlowSv.getBindRecordCount(po.getMonitoringId(), po.getFlowmeterId(), (byte) 2)).orElse(0); | 
|---|
|  |  |  | if (recordCount > 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.STATION_FLOWMETER_HAS_UNBOUND.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrMonitoringFlowmeter prMonitoringFlowmeter = DtoToMoniFlowPojo.INSTANCT.po2vo(po); | 
|---|
|  |  |  | Date operateTime = new Date(); | 
|---|
|  |  |  | prMonitoringFlowmeter .setOperatedt(operateTime); | 
|---|
|  |  |  | prMonitoringFlowmeter.setOperatetype((byte)1); | 
|---|
|  |  |  | prMonitoringFlowmeter.setOperatedt(operateTime); | 
|---|
|  |  |  | prMonitoringFlowmeter.setOperatetype((byte) 2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrFlowmeter flowmeter = new PrFlowmeter(); | 
|---|
|  |  |  | flowmeter.setMonitoringId(null); | 
|---|
|  |  |  | flowmeter.setId(po.getFlowmeterId()); | 
|---|
|  |  |  | flowmeter.setOperator(po.getOperator()); | 
|---|
|  |  |  | flowmeter.setOperateDt(operateTime); | 
|---|
|  |  |  | Integer shu = flowmeterSv.flowmeterAddMonId(flowmeter); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer rec = Optional.ofNullable(moniFlowSv.addRecord(prMonitoringFlowmeter)).orElse(0); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | if (rec == 0 || shu == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据监测站编号获取绑定记录 按操作时间降序 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param monitoringId 监测站编号 | 
|---|
|  |  |  | * @return 绑定记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获取绑定记录", description = "返回获取绑定记录") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回绑定记录(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = PrMonitoringFlowmeter.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "bingRecords/{monitoringId}") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<List<Map<String, Object>>> getBingRecordsByMonitoringId(@PathVariable("monitoringId") String monitoringId) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<Map<String, Object>> list = Optional.ofNullable(moniFlowSv.getBingRecordsByMonitoringId(monitoringId)).orElse(new ArrayList<>()); | 
|---|
|  |  |  | if (list.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.NO_MONITORING_FLOWMETERS.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(list); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询绑定记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|