New file |
| | |
| | | package com.dy.pipIrrBase.rtuUpgrade.task; |
| | | |
| | | 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.pojoUg.UgRtuController; |
| | | import com.dy.pipIrrGlobal.voPr.VoController; |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/11/7 11:33 |
| | | * @Description |
| | | */ |
| | | @Slf4j |
| | | @Tag(name = "选择RTU升级任务对应的控制器", description = "选择RTU升级任务对应的控制器并添加等操作") |
| | | @RestController |
| | | @RequestMapping(path = "ugRtuAddController") |
| | | @SuppressWarnings("unchecked") |
| | | //java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") |
| | | public class UgRtuAddControllerCtrl { |
| | | |
| | | private UgRtuAddControllerSv addSv; |
| | | private UgRtuControllerSv addedSv; |
| | | |
| | | @Autowired |
| | | private void setAddSv(UgRtuAddControllerSv addSv) { this.addSv = addSv; } |
| | | |
| | | @Autowired |
| | | private void setSv(UgRtuControllerSv addedSv) { this.addedSv = addedSv; } |
| | | |
| | | /** |
| | | * 客户端请求得到一些控制器信息,以供被选择为升级对象 |
| | | * @return 一些控制器信息 |
| | | */ |
| | | @Operation(summary = "得到一些控制器信息,以供被选择为升级对象", description = "得到一些控制器信息,以供被选择为升级对象") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "返回一些RTU升级任务数据(BaseResponse.content:QueryResultVo[{}])", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = VoController.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "/some") |
| | | @SsoAop() |
| | | public BaseResponse<QueryResultVo<List<VoController>>> some(QueryAddControllerVo vo){ |
| | | try { |
| | | QueryResultVo<List<VoController>> res = this.addSv.selectSome(vo) ; |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询RTU升级任务异常", e); |
| | | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 把符合条件的控制器选择为升级任务对象 |
| | | * @return 一些RTU升级任务数据 |
| | | */ |
| | | @Operation(summary = "把符合条件的控制器选择为升级任务对象", description = "把符合条件的控制器选择为升级任务对象") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "返回一些RTU升级任务数据(BaseResponse.content:QueryResultVo[{}])", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = UgRtuAddSomeResVo.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "/addSome") |
| | | @SsoAop() |
| | | public BaseResponse<UgRtuAddSomeResVo> addSome(QueryAddControllerVo vo){ |
| | | if(vo.taskId == null){ |
| | | return BaseResponseUtils.buildErrorMsg("升级任务id不能为空") ; |
| | | } |
| | | UgRtuAddSomeResVo res = new UgRtuAddSomeResVo(); |
| | | try { |
| | | List<VoController> list = this.addSv.selectAll(vo) ; |
| | | List<UgRtuController> addedList = this.addedSv.selectAllConByTask(vo.taskId) ; |
| | | if(list != null && list.size() > 0){ |
| | | if(addedList == null || addedList.size() == 0){ |
| | | for(VoController voCon : list){ |
| | | UgRtuController ugRtuController = new UgRtuController(); |
| | | ugRtuController.setTaskId(vo.taskId); |
| | | ugRtuController.setControllerId(Long.parseLong(voCon.getId())) ; |
| | | ugRtuController.setRtuAddr(voCon.getRtuAddr()) ; |
| | | this.addedSv.save(ugRtuController); |
| | | res.successAddTotal += 1; |
| | | } |
| | | }else{ |
| | | boolean exist = false ; |
| | | for(VoController voCon : list){ |
| | | exist = false ; |
| | | for(UgRtuController addedVo : addedList){ |
| | | if(addedVo.controllerId.longValue() == (Long.parseLong(voCon.getId()))){ |
| | | exist = true; |
| | | break; |
| | | } |
| | | } |
| | | if(!exist){ |
| | | UgRtuController ugRtuController = new UgRtuController(); |
| | | ugRtuController.setTaskId(vo.taskId); |
| | | ugRtuController.setControllerId(Long.parseLong(voCon.getId())) ; |
| | | ugRtuController.setRtuAddr(voCon.getRtuAddr()) ; |
| | | this.addedSv.save(ugRtuController); |
| | | res.successAddTotal += 1; |
| | | }else{ |
| | | res.failRepeatAddTotal += 1; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("查询RTU升级任务异常", e); |
| | | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 把一个控制器选择为升级任务对象 |
| | | * @return 一些RTU升级任务数据 |
| | | */ |
| | | @Operation(summary = "把一个控制器选择为升级任务对象", description = "把一个控制器选择为升级任务对象") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "返回一些RTU升级任务数据(BaseResponse.content:QueryResultVo[{}])", |
| | | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "/addOne") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> addOne(String taskId, String controllerId, String rtuAddr){ |
| | | if(taskId == null || taskId.trim().equals("") |
| | | || controllerId == null || controllerId.trim().equals("") |
| | | || rtuAddr == null || rtuAddr.trim().equals("")){ |
| | | return BaseResponseUtils.buildErrorMsg("参数必须提供") ; |
| | | } |
| | | try { |
| | | if(this.addedSv.exist(Long.parseLong(taskId), Long.parseLong(controllerId))){ |
| | | return BaseResponseUtils.buildErrorMsg("该控制器已经添加过该任务") ; |
| | | }else{ |
| | | UgRtuController ugRtuController = new UgRtuController(); |
| | | ugRtuController.setTaskId(Long.parseLong(taskId)); |
| | | ugRtuController.setControllerId(Long.parseLong(controllerId)) ; |
| | | ugRtuController.setRtuAddr(rtuAddr) ; |
| | | int count = this.addedSv.save(ugRtuController); |
| | | if(count <= 0){ |
| | | return BaseResponseUtils.buildErrorMsg("数据库存储失败") ; |
| | | }else{ |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("查询RTU升级任务异常", e); |
| | | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; |
| | | } |
| | | } |
| | | } |