From 195945efc5db921a4c9eb8cf9421c172273293f5 Mon Sep 17 00:00:00 2001
From: Administrator <hbal>
Date: 星期五, 21 四月 2023 08:40:51 +0800
Subject: [PATCH] LED投屏功能优化

---
 JavaSource/com/mandi/webservice/service/impl/FdXSTDService.java |  173 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 104 insertions(+), 69 deletions(-)

diff --git a/JavaSource/com/mandi/webservice/service/impl/FdXSTDService.java b/JavaSource/com/mandi/webservice/service/impl/FdXSTDService.java
index fed4699..3698132 100644
--- a/JavaSource/com/mandi/webservice/service/impl/FdXSTDService.java
+++ b/JavaSource/com/mandi/webservice/service/impl/FdXSTDService.java
@@ -8,6 +8,7 @@
 import com.mandi.basicconfig.mapper.NczsjMapper;
 import com.mandi.basicconfig.persist.*;
 import com.mandi.common.JSONobj;
+import com.mandi.common.Jacksonmethod;
 import com.mandi.common.ParamFileter.BigDecimalfiter;
 import com.mandi.common.SpringContext;
 import com.mandi.common.Wxhtmethod;
@@ -588,17 +589,21 @@
 		 // 姝ゅ寮傛瑙﹀彂涓�涓嬫槑鏅熷彂杞�
 		if("06".equals(fdb.getSdepartNo())) {
 			final String cph = currPch;
+			final String finalVehicleId = vehicleId;
 			ThreadPoolUtil.getInstance().execute(()->{
+				synchronized (FdXSTDService.refreshMsLedLock) {
+					if (FdXSTDService.refreshMsLedLock) { // 绯荤粺绻佸繖
+						log.info(finalVehicleId + "" + cph + "绯荤粺绻佸繖锛�");
+						return;
+					}
+				}
 				try {
 					synchronized (FdXSTDService.refreshMsLedLock) {
-						if (FdXSTDService.refreshMsLedLock) { // 绯荤粺绻佸繖
-							return  ;
-						}
 						FdXSTDService.refreshMsLedLock = true;
 					}
 					sendToMsLed(cph);
 				} catch (Exception e) {
-					log.error(e);
+					log.error("鍑虹幇寮傚父锛�"+ e.getMessage(),e);
 				} finally {
 					synchronized (FdXSTDService.refreshMsLedLock) {
 						FdXSTDService.refreshMsLedLock = false;
@@ -646,6 +651,10 @@
 		Map<String,List<Map>> ywbhListMap = new HashMap<>();
 		for (Map map : totalList) {
 			String ywdw = (String) map.get("tdmx_fdywbh");
+			if(ywdw == null) {
+				log.info("鍑虹幇涓氬姟鍗曞彿涓簄ull鐨勬儏鍐碉細" + Jacksonmethod.tojson(map,false));
+				continue;
+			}
 			if(ywbhListMap.get(ywdw) == null) {
 				ywbhListMap.put(ywdw, new ArrayList<>());
 			}
@@ -655,18 +664,14 @@
 		//"(杞︾墝鍙�)\\-(A鍖哄凡瑁呰溅)/(A鍖烘�昏)\\-(B鍖哄凡瑁呰溅)/(B鍖烘�昏)\\-(C鍖哄凡瑁呰溅)/(C鍖烘�昏)\\r\\n";
 		String formatStr = "%s %s/%s %s/%s %s/%s\r\n";
 		// 鍙湁1涓尯
-		String speakTxtFormatStr1 = "杞﹀彿%s 锛岃璐�%d浠跺凡瀹屾垚锛岃鍙告満娓呯偣璐х墿鍚庡敖蹇┒绂昏璐у尯銆�";
-		// 鍙湁2涓尯
-		String speakTxtFormatStr2 = "杞﹀彿%s锛�%s鍖鸿璐�%d浠跺凡鍏ㄩ儴鎵弿瀹屾垚锛岃鍙告満娓呯偣璐х墿鍚庡幓%s鍖鸿璐с��";
-		// 鍙湁3涓尯
-		String speakTxtFormatStr3 = "杞﹀彿%s锛�%s鍖鸿璐�%d浠跺凡鍏ㄩ儴鎵弿瀹屾垚锛岃鍙告満娓呯偣璐х墿鍚庡幓%s鍖�%s鍖鸿璐с��";
+
 		Map speakParam = new HashMap(1);
 		for (Map.Entry<String, List<Map>> entry : ywbhListMap.entrySet()) {
 			// 閬嶅巻姣忎釜涓氬姟鍗曠殑
 			// 褰撳墠瑁呰溅A銆丅銆丆鍖�
 			boolean currA = false,currB = false, currC = false;
 			boolean hasZcwc = false; // 淇濊瘉宸茬粡瀹屾垚浜�
-			// String ywhb = entry.getKey();
+			String ywhb = entry.getKey();
 			List<Map> vehicleIdTotalList = entry.getValue();
 			Map<String, Integer> totalAbcMap = new HashMap(3); // 鎬昏淇℃伅
 			totalAbcMap.put("A", 0);
@@ -680,7 +685,7 @@
 			for (Map map : vehicleIdTotalList) {
 				String hw = (String) map.get("tdmx_hwmc");
 				String pch = (String) map.get("tdmx_pch");
-				if("".equals(cph))  cph = (String) map.get("tdmx_fdcph");
+				if(StringUtils.isBlank(cph))  cph = (String) map.get("tdmx_fdcph");
 				Integer zcbz = (Integer) map.get("tdmx_zcbz");
 				String hh = hw.replaceAll("\\-.*","");
 				hh = hh.substring(hh.length()-2); // 鍙栨渶鍚庝袱浣�
@@ -719,77 +724,35 @@
 					totalAbcMap.get("A") + totalAbcMap.get("B") + totalAbcMap.get("C")) { // 闈炲綋鍓嶈溅鐗屽彿锛屽凡缁忚杞﹀畬鎴愪絾鏄湭鍑哄巶
 				continue;
 			}*/
+			if(totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0 && totalAbcMap.get("A")==0) {
+				continue;
+			}
 			str2 += String.format(formatStr, cph, fillWithZero(abcMap.get("A")), fillWithZero(totalAbcMap.get("A")),
 					fillWithZero(abcMap.get("B")), fillWithZero(totalAbcMap.get("B")),
 					fillWithZero(abcMap.get("C")), fillWithZero(totalAbcMap.get("C")));
+			log.info(ywhb +  "鎶曞睆鍑嗗瀹屾垚锛屽紑濮嬪噯澶囪闊炽��");
 			// 寮�濮嬪噯澶囪闊�
 			int total = 0;
-			if(currA && abcMap.get("A") == totalAbcMap.get("A")) { // 褰撳墠杞﹀湪A鍖鸿杞﹀畬鎴�
+			if(currA && abcMap.get("A") == totalAbcMap.get("A") && totalAbcMap.get("A")>0) { // 褰撳墠杞﹀湪A鍖鸿杞﹀畬鎴�
 				total = totalAbcMap.get("A");
 			}
-			if(currB && abcMap.get("B") == totalAbcMap.get("B")) {// 褰撳墠杞﹀湪B鍖鸿杞﹀畬鎴�
+			if(currB && abcMap.get("B") == totalAbcMap.get("B") && totalAbcMap.get("B")>0) {// 褰撳墠杞﹀湪B鍖鸿杞﹀畬鎴�
 				total = totalAbcMap.get("B");
 			}
-			if(currC && abcMap.get("C") == totalAbcMap.get("C")) {// 褰撳墠杞﹀湪C鍖鸿杞﹀畬鎴�
+			if(currC && abcMap.get("C") == totalAbcMap.get("C") && totalAbcMap.get("C")>0) {// 褰撳墠杞﹀湪C鍖鸿杞﹀畬鎴�
 				total = totalAbcMap.get("C");
 			}
-			if(total > 0) { // 鎾斁璇煶锛岃绂诲紑鍖哄煙
-				speakParam.clear();
-				String speakTxt=null ;
-				if( (abcMap.get("A")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0) ||
-						(abcMap.get("B")>0  && totalAbcMap.get("A")==0 && totalAbcMap.get("C")==0)  ||
-						(abcMap.get("C")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("D")==0)
-				) { // 鍙湁涓�涓尯鍩熸湁璐х墿
-					speakTxt= String.format(speakTxtFormatStr1, cph, total);
-				}else  if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 &&
-						(totalAbcMap.get("C")==0 || totalAbcMap.get("C") == abcMap.get("C"))){ // AB閮芥湁璐� C鍖哄凡瀹屾垨鏃犺揣
-					if(totalAbcMap.get("C")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { // C瑁呭畬AB鏈瀹�
-						speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
-					} else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { //A瀹孊鏈畬
-						speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "B");
-					}else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("A")< totalAbcMap.get("A")) {//B瀹孉鏈畬
-						speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "A");
-					}else { // 鍏ㄩ儴瑁呭畬
-						speakTxt= String.format(speakTxtFormatStr1, cph, total);
-					}
-				}else if(totalAbcMap.get("C")>0 && totalAbcMap.get("B")>0 &&
-						(totalAbcMap.get("A")==0 || totalAbcMap.get("A") == abcMap.get("A")) ){ //BC鏈夎揣 A鍖哄凡瀹屾垨鏃犺揣
-					if(totalAbcMap.get("A")>0 && abcMap.get("C")< totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) {  // A瑁呭畬BC鏈瀹�
-						speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
-					} else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) { // C瀹孊鏈瀹�
-						speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "B");
-					}else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("C")< totalAbcMap.get("C")) {// B瀹孋鏈瀹�
-						speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "C");
-					}else { // 鍏ㄩ儴瑁呭畬
-						speakTxt= String.format(speakTxtFormatStr1, cph, total);
-					}
-				}else  if (totalAbcMap.get("A")>0 && totalAbcMap.get("C")>0 &&
-						(totalAbcMap.get("B")==0 || totalAbcMap.get("B") == abcMap.get("B")) ) { //AC鏈夎揣
-					if(totalAbcMap.get("B")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) {
-						speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
-					} else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) { // A瑁呭畬C鏈瀹�
-						speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "C");
-					}else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("A")< totalAbcMap.get("A")) {// C瑁呭畬A鏈瀹�
-						speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "A");
-					}else { // 鍏ㄩ儴瑁呭畬
-						speakTxt= String.format(speakTxtFormatStr1, cph, total);
-					}
-				}else if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 && totalAbcMap.get("C")>0) { // 3鍖洪兘鏈夎揣鐗╋紝涓斿彧鏈変竴涓彇瑁呭畬浜�
-					if(abcMap.get("A")>0 && abcMap.get("B")<totalAbcMap.get("B") && abcMap.get("C")<totalAbcMap.get("C")) {
-						speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
-					} else if(abcMap.get("B")>0 && abcMap.get("C")==0 && abcMap.get("A")==0) {
-						speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
-					} else if(abcMap.get("C")>0 && abcMap.get("A")==0 && abcMap.get("B")==0) {
-						speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
-					} else { // 鍏ㄩ儴瑁呭畬
-						speakTxt= String.format(speakTxtFormatStr1, cph, total);
-					}
-				} else {
-					speakTxt= String.format(speakTxtFormatStr1, cph, total);
+			try {
+				String speakTxt = startToSpeak(cph,total,abcMap,totalAbcMap);
+				if(StringUtils.isNotBlank(speakTxt)) {
+					log.info("SpeakTxt:"+ speakTxt);
+					speakParam.put("SpeakTxt", speakTxt);
 				}
-				speakParam.put("SpeakTxt", speakTxt);
-				log.info("SpeakTxt:"+ speakTxt);
+			}catch (Exception e){
+				log.error("鍑嗗璇煶鍑洪敊锛�" + e.getMessage(),e);
 			}
+
+			// 鍑嗗璇煶缁撴潫
 			// 鍗曡締杞︾殑鍗曚釜涓氬姟鍗曠殑淇℃伅缁撴潫
 		}
 		if(StringUtils.isBlank(str2)) {
@@ -809,6 +772,78 @@
 
 	}
 
+	/**
+	 * 鍑嗗璇煶
+	 * @param cph 杞︾墝鍙�
+	 * @param total 褰撳墠鍖烘�绘暟
+	 * @param abcMap A銆丅銆丆涓簁ey鐨勫尯宸茶鏁扮洰
+	 * @param totalAbcMap A銆丅銆丆涓簁ey鐨勫尯鎬绘暟
+	 * @return
+	 */
+	String startToSpeak(String cph, int total,Map<String,Integer> abcMap,Map<String,Integer> totalAbcMap) {
+		String speakTxt=null ;
+		if(total > 0) { // 鎾斁璇煶锛岃绂诲紑鍖哄煙
+			String speakTxtFormatStr1 = "杞﹀彿%s 锛岃璐�%d浠跺凡瀹屾垚锛岃鍙告満娓呯偣璐х墿鍚庡敖蹇┒绂昏璐у尯銆�";
+			// 鍙湁2涓尯
+			String speakTxtFormatStr2 = "杞﹀彿%s锛�%s鍖鸿璐�%d浠跺凡鍏ㄩ儴鎵弿瀹屾垚锛岃鍙告満娓呯偣璐х墿鍚庡幓%s鍖鸿璐с��";
+			// 鍙湁3涓尯
+			String speakTxtFormatStr3 = "杞﹀彿%s锛�%s鍖鸿璐�%d浠跺凡鍏ㄩ儴鎵弿瀹屾垚锛岃鍙告満娓呯偣璐х墿鍚庡幓%s鍖�%s鍖鸿璐с��";
+
+			if( (abcMap.get("A")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("C")==0) ||
+					(abcMap.get("B")>0  && totalAbcMap.get("A")==0 && totalAbcMap.get("C")==0)  ||
+					(abcMap.get("C")>0  && totalAbcMap.get("B")==0 && totalAbcMap.get("D")==0)
+			) { // 鍙湁涓�涓尯鍩熸湁璐х墿
+				speakTxt= String.format(speakTxtFormatStr1, cph, total);
+			}else  if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 &&
+					(totalAbcMap.get("C")==0 || totalAbcMap.get("C") == abcMap.get("C"))){ // AB閮芥湁璐� C鍖哄凡瀹屾垨鏃犺揣
+				if(totalAbcMap.get("C")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { // C瑁呭畬AB鏈瀹�
+					speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
+				} else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("B")< totalAbcMap.get("B")) { //A瀹孊鏈畬
+					speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "B");
+				}else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("A")< totalAbcMap.get("A")) {//B瀹孉鏈畬
+					speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "A");
+				}else { // 鍏ㄩ儴瑁呭畬
+					speakTxt= String.format(speakTxtFormatStr1, cph, total);
+				}
+			}else if(totalAbcMap.get("C")>0 && totalAbcMap.get("B")>0 &&
+					(totalAbcMap.get("A")==0 || totalAbcMap.get("A") == abcMap.get("A")) ){ //BC鏈夎揣 A鍖哄凡瀹屾垨鏃犺揣
+				if(totalAbcMap.get("A")>0 && abcMap.get("C")< totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) {  // A瑁呭畬BC鏈瀹�
+					speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
+				} else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("B")< totalAbcMap.get("B")) { // C瀹孊鏈瀹�
+					speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "B");
+				}else if(abcMap.get("B")== totalAbcMap.get("B") && abcMap.get("C")< totalAbcMap.get("C")) {// B瀹孋鏈瀹�
+					speakTxt = String.format(speakTxtFormatStr2, cph, "B", total, "C");
+				}else { // 鍏ㄩ儴瑁呭畬
+					speakTxt= String.format(speakTxtFormatStr1, cph, total);
+				}
+			}else  if (totalAbcMap.get("A")>0 && totalAbcMap.get("C")>0 &&
+					(totalAbcMap.get("B")==0 || totalAbcMap.get("B") == abcMap.get("B")) ) { //AC鏈夎揣
+				if(totalAbcMap.get("B")>0 && abcMap.get("A")< totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) {
+					speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
+				} else if(abcMap.get("A")== totalAbcMap.get("A") && abcMap.get("C")< totalAbcMap.get("C")) { // A瑁呭畬C鏈瀹�
+					speakTxt = String.format(speakTxtFormatStr2, cph, "A", total, "C");
+				}else if(abcMap.get("C")== totalAbcMap.get("C") && abcMap.get("A")< totalAbcMap.get("A")) {// C瑁呭畬A鏈瀹�
+					speakTxt = String.format(speakTxtFormatStr2, cph, "C", total, "A");
+				}else { // 鍏ㄩ儴瑁呭畬
+					speakTxt= String.format(speakTxtFormatStr1, cph, total);
+				}
+			}else if(totalAbcMap.get("A")>0 && totalAbcMap.get("B")>0 && totalAbcMap.get("C")>0) { // 3鍖洪兘鏈夎揣鐗╋紝涓斿彧鏈変竴涓彇瑁呭畬浜�
+				if(abcMap.get("A")>0 && abcMap.get("B")<totalAbcMap.get("B") && abcMap.get("C")<totalAbcMap.get("C")) {
+					speakTxt= String.format(speakTxtFormatStr3, cph,"A", total,"B","C");
+				} else if(abcMap.get("B")>0 && abcMap.get("C")==0 && abcMap.get("A")==0) {
+					speakTxt= String.format(speakTxtFormatStr3, cph,"B", total,"A","C");
+				} else if(abcMap.get("C")>0 && abcMap.get("A")==0 && abcMap.get("B")==0) {
+					speakTxt= String.format(speakTxtFormatStr3, cph,"C", total,"A","B");
+				} else { // 鍏ㄩ儴瑁呭畬
+					speakTxt= String.format(speakTxtFormatStr1, cph, total);
+				}
+			} else {
+				speakTxt= String.format(speakTxtFormatStr1, cph, total);
+			}
+		}
+		return speakTxt;
+	}
+
 	@Override
 	public void sendToYrLed(String currPch) {
 			// 鐘舵�� 涓�纾呭悗锛屽緟瑁咃紱PDA鎵爜 鍦ㄨ锛� 浜屾杩囩鍚庢秷澶�

--
Gitblit v1.9.3