From 7aab004601e77890b158f19d1735594a8326feaa Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 24 四月 2025 17:11:17 +0800 Subject: [PATCH] 数据库事务注解位置调整 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/parse/Cd_A2_Down.java | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 215 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/parse/Cd_A2_Down.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/parse/Cd_A2_Down.java new file mode 100644 index 0000000..993e94d --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V2/parse/Cd_A2_Down.java @@ -0,0 +1,215 @@ +package com.dy.common.mw.protocol.p206V2.parse; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.dy.common.mw.protocol.*; +import com.dy.common.mw.protocol.p206V2.CodeV2; +import com.dy.common.mw.protocol.p206V2.CommonV2; +import com.dy.common.mw.protocol.p206V2.ParseParamsForDownV2; +import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2; +import com.dy.common.mw.protocol.p206V2.downVos.ComA2Vo; +import com.dy.common.mw.protocol.p206V2.parse.global.GlCreate; +import com.dy.common.util.ByteUtil; + +/** + * @Author liurunyu + * @Date 2024/06/12 9:30 + * @Description + */ +@AnnotationCodeDown(ifAny={ + CodeV2.cd_A2 +}) +public class Cd_A2_Down implements CodeParse { + + @Override + public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { + ParseParamsForDownV2 para = (ParseParamsForDownV2) params ; + MidResultToRtu midRs = new MidResultToRtu() ; + byte[] bs = this.doParse(midRs, para) ; + + midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;//rtu杩斿洖鍛戒护缁撴灉 鍙戝悜鐩殑鍦皐eb URL + midRs.protocolName = para.protocolName ;//鍗忚鍚嶇О + midRs.protocolVersion = para.protocolVersion ;//鍗忚鐗堟湰鍙� + midRs.rtuAddr = para.rtuAddr ;//Rtu鍦板潃 + midRs.commandId = para.commandId ;//鍛戒护ID锛屽彂璧峰懡浠ょ殑瀹㈡埛绔�(web绔�)鐢熸垚锛屼互鍖归厤鍛戒护缁撴灉 + midRs.downCode = para.commandCode ;//涓嬭鍛戒护鍔熻兘鐮�; + midRs.downCodeName = CodeV2.getCodeName(para.commandCode) ;//涓嬭鍛戒护鍔熻兘鐮佸悕绉�; + midRs.downBuffer = bs ;//涓嬭鍛戒护鏁版嵁 + midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//涓嬭鍛戒护鏁版嵁鍗佸叚杩涘埗褰㈠紡 + midRs.hasResponse = true ;//鏄惁鏈夊簲绛� + midRs.maxSendTimes = null ;//鍛戒护鏈�澶у彂閫佹鏁�(褰撴敹涓嶅埌搴旂瓟鏃讹紝灏嗛噸鍙�)锛屽鏋滀笉璁剧疆锛屽懡浠ょ紦瀛樺櫒杩涜琛ュ厖璁剧疆 + midRs.isCachForOffLine = false ;//RTU涓嶅湪绾匡紝鍛戒护鏄惁缂撳瓨锛屼綆鍔熻�楁椂涓簍rue + + if(isLowPower != null && isLowPower.booleanValue()){ + //浣庡姛鑰楁椂锛屽敖蹇彂閫� + midRs.isQuickSend = true ; + } + + return new MidResult[]{midRs} ; + } + + /** + * 鏋勯�犱笅琛屾暟鎹� + * @param midRs 鍙傛暟 + * @param para 鍙傛暟 + * @return 瀛楄妭鏁扮粍 + * @throws Exception 寮傚父 + */ + public byte[] doParse(MidResultToRtu midRs, ParseParamsForDownV2 para) throws Exception { + CommonV2 commonV_1 = new CommonV2() ; + byte[] bytes ; + byte[] bsHead = new byte[ProtocolConstantV206V2.lenHead2Code] ; + byte index = GlCreate.createHead(para.protocolVersion, bsHead); + + index++ ; + bsHead[index] = commonV_1.createCtrl((byte)0, (byte)0) ; + + index++ ; + GlCreate.createRtuAddr4P206(para.rtuAddr, bsHead, index); + index += 5 ; + + ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; + + JSONObject obj = (JSONObject)para.param; + String json = obj.toJSONString(); + ComA2Vo cvo = JSON.parseObject(json, ComA2Vo.class) ; + if(cvo == null){ + throw new Exception("json杞珻omA0Vo涓簄ull") ; + } + if(cvo.icCardNo == null){ + throw new Exception("铏氭嫙IC鍗$紪鍙蜂笉鑳戒负绌�") ; + } + if(cvo.moneyRemain == null || cvo.moneyRemain == 0.0){ + throw new Exception("鍓╀綑閲戦涓嶈兘涓虹┖鎴栦负0") ; + } + if(cvo.waterPrice == null || cvo.waterPrice == 0.0){ + throw new Exception("姘翠环涓嶈兘涓虹┖鎴栦负0") ; + } + if(cvo.waterAmount == null || cvo.waterAmount == 0.0){ + throw new Exception("棰勭敤姘撮噺涓嶈兘涓虹┖鎴栦负0") ; + } + if(cvo.waterAmount < 0 || cvo.waterAmount > 9999){ + throw new Exception("棰勭敤姘撮噺鍙栧�艰寖鍥存槸0~9999m3") ; + } + if(cvo.year == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---骞翠笉鑳戒负绌�") ; + } + if(cvo.year < 24 || cvo.year > 9999){ + throw new Exception("璁″垝寮�闃�鏃堕棿---骞翠笉姝g‘") ; + } + if(cvo.year > 99 && cvo.year < 2024){ + throw new Exception("璁″垝寮�闃�鏃堕棿---骞翠笉姝g‘") ; + } + if(cvo.month == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏈堜笉鑳戒负绌�") ; + } + if(cvo.month < 1 || cvo.month > 12){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏈堜笉姝g‘") ; + } + if(cvo.day == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃ヤ笉鑳戒负绌�") ; + } + if(cvo.day < 1 || cvo.day > 31){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃ヤ笉姝g‘") ; + } + if(cvo.hour == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃朵笉鑳戒负绌�") ; + } + if(cvo.hour < 0 || cvo.hour > 23){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃朵笉姝g‘") ; + } + if(cvo.minute == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃朵笉鑳戒负绌�") ; + } + if(cvo.minute < 0 || cvo.minute > 59){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鍒嗕笉姝g‘") ; + } + + //String[] icCardNoGrp = CommonV2.dealIcCardNo(cvo.icCardNo) ; + //if(icCardNoGrp[0] != null){ + // midRs.param = icCardNoGrp[0] ; + //} + //ByteUtil.string2BCD_LE(bs, icCardNoGrp[1], index) ; + byte[] bs = new byte[8] ; + index = 0 ; + GlCreate.createIcCardNo(cvo.icCardNo, bs, 0); + bytes = ByteUtil.bytesMerge(bsHead, bs) ; + + bs = new byte[4] ; + index = 0 ; + Integer money = Double.valueOf(cvo.moneyRemain * 100.0D).intValue() ; + byte[] bTemp = ByteUtil.int2BCD_LE(money) ; + int bTempLen = bTemp.length ; + int count = 0 ; + for(int i = 0 ; i < bTempLen; i++){ + bs[index++] = bTemp[i] ; + count ++ ; + if(count >= 4){ + break ; + } + } + for(; count < 4; count++){ + bs[index++] = 0 ; + } + bytes = ByteUtil.bytesMerge(bytes, bs) ; + + bs = new byte[2] ; + index = 0 ; + Integer price = Double.valueOf(cvo.waterPrice * 100.0D).intValue() ; + bTemp = ByteUtil.int2BCD_LE(price) ; + bTempLen = bTemp.length ; + count = 0 ; + for(int i = 0 ; i < bTempLen; i++){ + bs[index++] = bTemp[i] ; + count ++ ; + if(count >= 2){ + break ; + } + } + for(; count < 2; count++){ + bs[index++] = 0 ; + } + bytes = ByteUtil.bytesMerge(bytes, bs) ; + + + bs = new byte[2] ; + index = 0 ; + bTemp = ByteUtil.int2BCD_LE(cvo.waterAmount) ; + bTempLen = bTemp.length ; + count = 0 ; + for(int i = 0 ; i < bTempLen; i++){ + bs[index++] = bTemp[i] ; + count ++ ; + if(count >= 2){ + break ; + } + } + for(; count < 2; count++){ + bs[index++] = 0 ; + } + bytes = ByteUtil.bytesMerge(bytes, bs) ; + + + bs = new byte[5] ; + if(cvo.year >= 2024){ + cvo.year = cvo.year - 2000 ; + } + bs[0] = ByteUtil.int2BCD_LE(cvo.minute)[0] ; + bs[1] = ByteUtil.int2BCD_LE(cvo.hour)[0] ; + bs[2] = ByteUtil.int2BCD_LE(cvo.day)[0] ; + bs[3] = ByteUtil.int2BCD_LE(cvo.month)[0] ; + bs[4] = ByteUtil.int2BCD_LE(cvo.year)[0] ; + + bytes = ByteUtil.bytesMerge(bytes, bs) ; + + GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑 + + byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓� + + bytes = ByteUtil.bytesMerge(bytes, bsTail) ; + + return bytes ; + } + +} + -- Gitblit v1.8.0