package com.dy.pipIrrProject.flowMonitoring;
|
|
import com.dy.common.aop.SsoAop;
|
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 io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
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.*;
|
|
/**
|
* @author ZhuBaoMin
|
* @date 2024-01-05 10:26
|
* @LastEditTime 2024-01-05 10:26
|
* @Description 管网流量监测站、流量计关联控制类
|
*/
|
|
@Slf4j
|
@Tag(name = "流量监测站、流量计关联管理", description = "流量监测站、流量计关联操作")
|
@RestController
|
@RequestMapping(path = "moni_flow")
|
@RequiredArgsConstructor
|
public class MoniFlowCtrl {
|
private final MoniFlowSv moniFlowSv;
|
|
private final FlowMonitoringSv flowMonitoringSv;
|
private final FlowmeterSv flowmeterSv;
|
|
/**
|
* 流量监测站绑定流量计
|
* 若流量监测站或流量计不存在需提示用户
|
* 若流量监测站已经与流量计绑定需提示用户
|
*
|
* @param po 绑定关系对象
|
* @param bindingResult
|
* @return
|
*/
|
@Operation(summary = "添加绑定记录", description = "添加绑定记录")
|
@ApiResponses(value = {
|
@ApiResponse(
|
responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
|
description = "操作结果:true:成功,false:失败(BaseResponse.content)",
|
content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
|
schema = @Schema(implementation = Boolean.class))}
|
)
|
})
|
@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()) {
|
return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
|
}
|
|
// 根据编号分别获取流量监测站、流量计未删除记录数
|
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) {
|
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);
|
|
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 || shu == 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage());
|
}
|
return BaseResponseUtils.buildSuccess(true);
|
}
|
|
@Operation(summary = "添加解绑记录", description = "添加解绑记录")
|
@ApiResponses(value = {
|
@ApiResponse(
|
responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
|
description = "操作结果:true:成功,false:失败(BaseResponse.content)",
|
content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
|
schema = @Schema(implementation = Boolean.class))}
|
)
|
})
|
@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()) {
|
return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
|
}
|
|
// 根据编号分别获取流量监测站、流量计未删除记录数
|
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) {
|
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) 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 || shu == 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage());
|
}
|
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());
|
}
|
}
|
}
|