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.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.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.Date;
|
import java.util.Objects;
|
import java.util.Optional;
|
|
/**
|
* @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.getRecordCountOfFlowMonitoring(po.getMonitoringId())).orElse(0);
|
Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeter(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);
|
|
Integer rec = Optional.ofNullable(moniFlowSv.addRecord(prMonitoringFlowmeter)).orElse(0);
|
if(rec == 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.getRecordCountOfFlowMonitoring(po.getMonitoringId())).orElse(0);
|
Integer recFlowmeter = Optional.ofNullable(flowmeterSv.getRecordCountOfFlowmeter(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)1);
|
|
Integer rec = Optional.ofNullable(moniFlowSv.addRecord(prMonitoringFlowmeter)).orElse(0);
|
if(rec == 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.MONITORING_FLOWMETER_BIND_FAIL.getMessage());
|
}
|
return BaseResponseUtils.buildSuccess(true) ;
|
}
|
}
|