package com.dy.pipIrrProject.intakeController;
|
|
import com.dy.common.aop.SsoAop;
|
import com.dy.common.webUtil.BaseResponse;
|
import com.dy.common.webUtil.BaseResponseUtils;
|
import com.dy.common.webUtil.QueryResultVo;
|
import com.dy.common.webUtil.ResultCodeMsg;
|
import com.dy.pipIrrGlobal.pojoBa.BaClient;
|
import com.dy.pipIrrGlobal.pojoPr.PrIntakeController;
|
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-02 9:18
|
* @LastEditTime 2024-01-02 9:18
|
* @Description
|
*/
|
|
@Slf4j
|
@Tag(name = "取水口/控制器关联管理", description = "取水口/控制器关联操作")
|
@RestController
|
@RequestMapping(path="intake_controller")
|
@RequiredArgsConstructor
|
public class IntakeControllerCtrl {
|
private final IntakeControllerSv intakeControllerSv;
|
|
/**
|
* 添加取水口/控制器捆绑记录
|
* 1. 判断取水口是否存在
|
* 2. 判断控制器是否存在
|
* 3. 判断取水口、控制器绑定关系是否已存在
|
*/
|
@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 DtoIntakeController po, BindingResult bindingResult){
|
if(bindingResult != null && bindingResult.hasErrors()){
|
return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
|
}
|
|
Integer recordCount = Optional.ofNullable(intakeControllerSv.getBindRecordCount(po.getIntakeId(), po.getControllerId(), (byte)1)).orElse(0);
|
if(recordCount > 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_HAS_BINDED_CONTROLLER.getMessage());
|
}
|
|
PrIntakeController prIntakeController = DtoToPojo.INSTANCT.po2vo(po);
|
Date operateTime = new Date();
|
prIntakeController.setOperatedt(operateTime);
|
prIntakeController.setOperatetype((byte)1);
|
|
Integer rec = Optional.ofNullable(intakeControllerSv.addRecord(prIntakeController)).orElse(0);
|
if(rec == 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.BIND_FAIL.getMessage());
|
}
|
return BaseResponseUtils.buildSuccess(true) ;
|
}
|
|
/**
|
* 添加取水口/控制器解绑记录
|
* 1. 判断取水口是否存在
|
* 2. 判断控制器是否存在
|
* 3. 判断取水口、控制器解绑关系是否已存在
|
*/
|
@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 DtoIntakeController po, BindingResult bindingResult){
|
if(bindingResult != null && bindingResult.hasErrors()){
|
return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
|
}
|
|
Integer recordCount = Optional.ofNullable(intakeControllerSv.getBindRecordCount(po.getIntakeId(), po.getControllerId(), (byte)2)).orElse(0);
|
if(recordCount > 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_CONTROLLER_HAS_UNBOUND.getMessage());
|
}
|
|
PrIntakeController prIntakeController = DtoToPojo.INSTANCT.po2vo(po);
|
Date operateTime = new Date();
|
prIntakeController.setOperatedt(operateTime);
|
prIntakeController.setOperatetype((byte)2);
|
|
Integer rec = Optional.ofNullable(intakeControllerSv.addRecord(prIntakeController)).orElse(0);
|
if(rec == 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.BIND_FAIL.getMessage());
|
}
|
return BaseResponseUtils.buildSuccess(true) ;
|
}
|
|
/**
|
* 根据取水口编号获取绑定记录列表
|
* @param intakeId 取水口编号
|
* @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 = BaClient.class))}
|
)
|
})
|
@GetMapping(path = "intake_binds")
|
@SsoAop()
|
public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getBindsByIntakeId(Long intakeId){
|
try {
|
List<Map<String, Object>> list = Optional.ofNullable(intakeControllerSv.getBindsByIntakeId(intakeId)).orElse(new ArrayList<>());
|
if(list.size() <= 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_NO_RECORDS.getMessage());
|
}
|
return BaseResponseUtils.buildSuccess(list);
|
} catch (Exception e) {
|
log.error("查询农户异常", e);
|
return BaseResponseUtils.buildException(e.getMessage()) ;
|
}
|
}
|
|
/**
|
* 根据控制器编号获取绑定记录列表
|
* @param controllerId 控制器编号
|
* @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 = BaClient.class))}
|
)
|
})
|
@GetMapping(path = "controller_binds")
|
@SsoAop()
|
public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getBindsByControllerId(Long controllerId){
|
try {
|
List<Map<String, Object>> list = Optional.ofNullable(intakeControllerSv.getBindsByControllerId(controllerId)).orElse(new ArrayList<>());
|
if(list.size() <= 0) {
|
return BaseResponseUtils.buildFail(ProjectResultCode.CONTROLLER_NO_RECORDS.getMessage());
|
}
|
return BaseResponseUtils.buildSuccess(list);
|
} catch (Exception e) {
|
log.error("查询农户异常", e);
|
return BaseResponseUtils.buildException(e.getMessage()) ;
|
}
|
}
|
}
|