| 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.UgRtuTask; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voUg.VoRtuTask; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Parameter; | 
|---|
|  |  |  | 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.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.UnsupportedEncodingException; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Author: liurunyu | 
|---|
|  |  |  | * @Date: 2024/11/7 11:33 | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "RTU升级任务管理", description = "RTU升级任务增删改查等操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path = "ugRtuTask") | 
|---|
|  |  |  | @SuppressWarnings("unchecked") | 
|---|
|  |  |  | //java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") | 
|---|
|  |  |  | public class UgRtuTaskCtrl { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private UgRtuTaskSv sv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setSv(UgRtuTaskSv sv) { this.sv = sv; } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到一个RTU升级任务数据 | 
|---|
|  |  |  | * @return 一个RTU升级任务数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "一个RTU升级任务", description = "得到一个RTU升级任务数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回一个RTU升级任务数据(BaseResponse.content:{})", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = UgRtuTask.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "one") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<UgRtuTask> one(Long id) throws UnsupportedEncodingException { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(this.sv.selectById(id) ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到一些RTU升级任务数据 | 
|---|
|  |  |  | * @return 一些RTU升级任务数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得一些RTU升级任务", description = "返回一些分页RTU升级任务数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回一些RTU升级任务数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = UgRtuTask.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/some") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<UgRtuTask>>> some(QueryTaskVo vo){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<UgRtuTask>> res = this.sv.selectSome(vo) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询RTU升级任务异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到所有升级任务记录ID和文件名称 ,以供其他应用下拉选择 | 
|---|
|  |  |  | * @return 所RTU升级任务文件名数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得一些RTU升级任务", description = "返回一些分页RTU升级任务数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回一些RTU升级任务数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = UgRtuTask.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/all") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<UgRtuTask>>> all(){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<UgRtuTask>> res = this.sv.selectAll() ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询RTU升级任务异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增保存RTU升级任务 | 
|---|
|  |  |  | * @param vo 新增保存RTU升级任务form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "保存RTU升级任务", description = "提交RTU升级任务数据(form表单),进行保存") | 
|---|
|  |  |  | @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 = "save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> save(@Parameter(description = "form表单数据", required = true) @Valid VoRtuTask vo, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | UgRtuTask po = new UgRtuTask(); | 
|---|
|  |  |  | vo.toPo(po); | 
|---|
|  |  |  | po.init(); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.save(po); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存RTU升级任务异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 为了保证升级任务的正确,不提供修改功能,如果上传错了,只能删除后重新上传 | 
|---|
|  |  |  | * @param po 保存RTU升级任务form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | *  */ | 
|---|
|  |  |  | @Operation(summary = "编辑修改片区", description = "提交片区数据(form表单),进行修改") | 
|---|
|  |  |  | @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 = "update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> update(@Parameter(description = "form表单数据", required = true) @Valid UgRtuTask po, @Parameter(hidden = true) BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(po.id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("无数据实体ID") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.update(po); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存实体数据异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库存储失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 执行RTU升级任务 | 
|---|
|  |  |  | * @param id RTU升级任务ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "执行RTU升级任务", description = "提交RTU升级任务ID,进行执行") | 
|---|
|  |  |  | @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))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "execute") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> execute(Long id){ | 
|---|
|  |  |  | if(id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("id不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.isOver(id) ; | 
|---|
|  |  |  | if(count > 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("任务已经结束,不能再执行") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | count = this.sv.isExecute(id) ; | 
|---|
|  |  |  | if(count > 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("任务已经执行,不能再执行") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | count = this.sv.execute(id); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("执行RTU升级任务异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库操作失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 结束RTU升级任务 | 
|---|
|  |  |  | * @param id RTU升级任务ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "结束RTU升级任务", description = "提交RTU升级任务ID,进行结束") | 
|---|
|  |  |  | @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))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "over") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> over(Long id){ | 
|---|
|  |  |  | if(id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("id不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try {count = this.sv.isOver(id) ; | 
|---|
|  |  |  | if(count > 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("任务已经结束,不用再结束") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | count = this.sv.over(id); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("结束RTU升级任务异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库操作失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除RTU升级任务 | 
|---|
|  |  |  | * @param id RTU升级任务ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "删除RTU升级任务", description = "提交RTU升级任务ID,进行逻辑删除") | 
|---|
|  |  |  | @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))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "delete") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(Long id){ | 
|---|
|  |  |  | if(id == null){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("id不能为空") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | count = this.sv.delete(id); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("删除RTU升级任务异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(count <= 0){ | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("数据库操作失败") ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|