From 9f3c4a33279f10ed420d604765487558ab0744f0 Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期五, 11 四月 2025 11:42:21 +0800 Subject: [PATCH] 获取已完成灌溉计划接口增加分页功能 --- pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/rtuUpgrade/program/UgRtuProgramCtrl.java | 264 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 264 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/rtuUpgrade/program/UgRtuProgramCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/rtuUpgrade/program/UgRtuProgramCtrl.java new file mode 100644 index 0000000..9cadf12 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/rtuUpgrade/program/UgRtuProgramCtrl.java @@ -0,0 +1,264 @@ +package com.dy.pipIrrBase.rtuUpgrade.program; + +import cn.hutool.core.util.HexUtil; +import com.dy.common.aop.SsoAop; +import com.dy.common.softUpgrade.parse.HexFileParse; +import com.dy.common.softUpgrade.parse.HexFileVo; +import com.dy.common.util.ByteUtil; +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.UgRtuProgram; +import com.dy.pipIrrGlobal.voUg.VoRtuProgram; +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.*; + +import java.io.UnsupportedEncodingException; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * @Author: liurunyu + * @Date: 2024/11/5 8:32 + * @Description + */ +@Slf4j +@Tag(name = "RTU鍗囩骇绋嬪簭绠$悊", description = "RTU鍗囩骇绋嬪簭澧炲垹鏀规煡绛夋搷浣�") +@RestController +@RequestMapping(path = "ugRtuProgram") +@SuppressWarnings("unchecked") +//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked") +public class UgRtuProgramCtrl { + + private UgRtuProgramSv sv; + + @Autowired + private void setSv(UgRtuProgramSv sv) { this.sv = sv; } + + /** + * 寰楀埌涓�涓猂TU鍗囩骇绋嬪簭鏁版嵁 + * @return 涓�涓猂TU鍗囩骇绋嬪簭鏁版嵁 + */ + @Operation(summary = "涓�涓猂TU鍗囩骇绋嬪簭", description = "寰楀埌涓�涓猂TU鍗囩骇绋嬪簭鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�涓猂TU鍗囩骇绋嬪簭鏁版嵁锛圔aseResponse.content:{}锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = UgRtuProgram.class))} + ) + }) + @GetMapping(path = "one") + @SsoAop() + public BaseResponse<UgRtuProgram> one(Long id) throws UnsupportedEncodingException { + UgRtuProgram po = this.sv.selectById(id) ; + if(po != null){ + if(po.programBytes != null && po.programBytes.length > 0){ + po.programString = HexUtil.encodeHexStr(po.programBytes) ; + } + if(po.fileBytes != null && po.fileBytes.length > 0){ + po.fileString = new String(po.fileBytes) ; + po.fileString = po.fileString.replaceAll("\\r\\n", "<br/>") ; + } + return BaseResponseUtils.buildSuccess(po); + }else{ + return BaseResponseUtils.buildErrorMsg("鏈煡璇㈠埌瀵瑰簲鐨勮褰�") ; + } + } + /** + * 瀹㈡埛绔姹傚緱鍒颁竴浜汻TU鍗囩骇绋嬪簭鏁版嵁 + * @return 涓�浜汻TU鍗囩骇绋嬪簭鏁版嵁 + */ + @Operation(summary = "鑾峰緱涓�浜汻TU鍗囩骇绋嬪簭", description = "杩斿洖涓�浜涘垎椤礡TU鍗囩骇绋嬪簭鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�浜汻TU鍗囩骇绋嬪簭鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = UgRtuProgram.class))} + ) + }) + @GetMapping(path = "/some") + @SsoAop() + public BaseResponse<QueryResultVo<List<UgRtuProgram>>> some(QueryVo vo){ + try { + QueryResultVo<List<UgRtuProgram>> res = this.sv.selectSome(vo) ; + return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鏌ヨRTU鍗囩骇绋嬪簭寮傚父", e); + return BaseResponseUtils.buildErrorMsg(e.getMessage()) ; + } + } + + /** + * 瀹㈡埛绔姹傚緱鍒版墍鏈夊崌绾х▼搴忚褰旾D鍜屾枃浠跺悕绉� 锛屼互渚涘叾浠栧簲鐢ㄤ笅鎷夐�夋嫨 + * @return 鎵�RTU鍗囩骇绋嬪簭鏂囦欢鍚嶆暟鎹� + */ + @Operation(summary = "鑾峰緱涓�浜汻TU鍗囩骇绋嬪簭", description = "杩斿洖涓�浜涘垎椤礡TU鍗囩骇绋嬪簭鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�浜汻TU鍗囩骇绋嬪簭鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = UgRtuProgram.class))} + ) + }) + @GetMapping(path = "/all") + @SsoAop() + public BaseResponse<QueryResultVo<List<UgRtuProgram>>> all(){ + try { + QueryResultVo<List<UgRtuProgram>> 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鍗囩骇绋嬪簭鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇濆瓨") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝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 VoRtuProgram vo, @Parameter(hidden = true) BindingResult bindingResult){ + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + if(vo.storeRamAddr == null + || vo.storeRamAddr.trim().equals("") + || vo.storeRamAddr.length() != 8 + || !HexUtil.isHexNumber(vo.storeRamAddr)){ + return BaseResponseUtils.buildErrorMsg("鍗囩骇绋嬪簭瀛樻斁鍦板潃(4瀛楄妭锛�8浣嶅崄鍏繘鍒舵暟)涓嶆纭�") ; + } + if(vo.startRamAddr == null + || vo.startRamAddr.trim().equals("") + || vo.startRamAddr.length() != 8 + || !HexUtil.isHexNumber(vo.startRamAddr)){ + return BaseResponseUtils.buildErrorMsg("绋嬪簭瑕嗙洊璧峰鍦板潃(4瀛楄妭锛�8浣嶅崄鍏繘鍒舵暟)涓嶆纭�") ; + } + if(vo.file == null){ + return BaseResponseUtils.buildErrorMsg("RTU绋嬪簭鏂囦欢蹇呴』涓婁紶") ; + } + String fileName = vo.file.getOriginalFilename() ; + if(this.sv.existFileName(fileName)){ + return BaseResponseUtils.buildErrorMsg("RTU绋嬪簭鏂囦欢鍚嶅凡瀛樺湪") ; + } + + HexFileVo fileVo = null ; + byte[] fileBytes = null ; + try{ + fileBytes = vo.file.getBytes() ; + if(fileBytes != null) { + HexFileParse fileParse = new HexFileParse(); + fileVo = fileParse.doParse(fileBytes); + } + }catch (Exception e){ + fileVo = null ; + return BaseResponseUtils.buildErrorMsg("瑙f瀽RTU绋嬪簭鏂囦欢寮傚父锛�" + e.getMessage()) ; + } + if(fileVo != null){ + UgRtuProgram po = new UgRtuProgram(); + po.hexFileName = fileName ; + po.programCalculateBytes = (int)fileVo.calculateBytes ; + po.programCrc16 = fileVo.bytesCrc16 ; + po.programBytes = fileVo.bytes; + po.fileBytes = fileBytes; + po.remark = vo.remark ; + po.dt = new Date(); + po.deleted = 0 ; + vo.toPo(po); + po.id = null ; + 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) ; + } + }else{ + return BaseResponseUtils.buildErrorMsg("瑙f瀽RTU绋嬪簭鏂囦欢寮傚父") ; + } + } + /** + * 涓轰簡淇濊瘉鍗囩骇绋嬪簭鐨勬纭紝涓嶆彁渚涗慨鏀瑰姛鑳斤紝濡傛灉涓婁紶閿欎簡锛屽彧鑳藉垹闄ゅ悗閲嶆柊涓婁紶 + * @param vo 淇濆瓨RTU鍗囩骇绋嬪簭form琛ㄥ崟瀵硅薄 + * @return 鏄惁鎴愬姛 + @Operation(summary = "缂栬緫淇敼鐗囧尯", description = "鎻愪氦鐗囧尯鏁版嵁锛坒orm琛ㄥ崟锛夛紝杩涜淇敼") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝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 VoRtuProgram vo, @Parameter(hidden = true) BindingResult bindingResult){ + } + */ + + /** + * 鍒犻櫎RTU鍗囩骇绋嬪簭 + * @param id RTU鍗囩骇绋嬪簭ID + * @return 鏄惁鎴愬姛 + */ + @Operation(summary = "鍒犻櫎RTU鍗囩骇绋嬪簭", description = "鎻愪氦RTU鍗囩骇绋嬪簭ID锛岃繘琛岄�昏緫鍒犻櫎") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝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) ; + } + } + +} -- Gitblit v1.8.0